php_guest Posted June 6, 2009 Share Posted June 6, 2009 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. 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'); } }); }); Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 6, 2009 Share Posted June 6, 2009 function validate (id) { return document.getElementById(id).value !== ''; } Quote Link to comment Share on other sites More sharing options...
php_guest Posted June 6, 2009 Author Share Posted June 6, 2009 sorry I don't understand what you mean by this. I don't understand why test is not passed via Example. Quote Link to comment Share on other sites More sharing options...
php_guest Posted June 6, 2009 Author Share Posted June 6, 2009 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'); } }); Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Would this alert the correct data? function validate (id) { window.alert(id); } if (document.getElementById("formid").value === "vrednost") window.validate("test"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.