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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.