SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a problem with a simple function

    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.

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

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will make more simple question. The problem is that 'test' is not passed. The following function alert undefined, but it should alert test.

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

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    This is one of those times when I have to say:
    Works for me.

    Code html4strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>Test</title>
    <style type="text/css">
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
    <script type="text/javascript">
    function validate(Example) {
        var isGood = true;
        alert(Example);
    }
    $(function() {
        if (document.getElementById('formid').value == 'vrednost') {
            validate('test');
        }
    });
    </script>
    </head>
    <body>
    <input type="text" id="formid" value="vrednost">
    </body>
    </html>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •