Jump to content

a problem with a simple function


php_guest

Recommended Posts

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');
          }
    });

});

Link to comment
https://forums.phpfreaks.com/topic/161206-a-problem-with-a-simple-function/
Share on other sites

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');
          }
    });

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.