Forum Moderators: open

Message Too Old, No Replies

a problem with a simple function

         

php_member

8:44 pm on Jun 6, 2009 (gmt 0)

10+ Year Member



I have no idea why the function is not working if I put on the 4th line Example instead of 'test'. So if I put if(document.getElementById('test').value=='') is working, if I put if(document.getElementById(Example).value=='') is not working. Why test is not passed via Example? It must be some dummy mistake I can not find it! Please help me.


function validate(Example) {
var isGood = true;
//validate test
if(document.getElementById('test').value=='')
{
isGood = false;
}

//return true or false
if (isGood== false)
{
alert (isGood);
}
return isGood;

}

$(function() {

$('#addquestion').click(function() {
$('<input id="test" type="text" name="text1" /><br />').appendTo('#to_moreoptions');

if(document.getElementById('formid').value=='vrednost')
{
validate('test');
}
});

});

php_member

11:16 pm on Jun 6, 2009 (gmt 0)

10+ Year Member



I will make more simple question. The problem is that 'test' is not passed. The following function alert undefined, but it should alert test.

function validate(Example) {
var isGood = true;
alert(Example);
}

$(function() {
//if I put validate('test') here, it will alert test
if(document.getElementById('formid').value=='vrednost')
{
validate('test');
}
});