Results 1 to 2 of 2

Thread: Basic program Help with if function

  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Basic program Help with if function

    I need to make a simple program where the user inputs into a text box a number, then clicks a button and another text box returns whether the number is greater or less than 20. I know its an if function but not sure what to put. Also does this require parsefloat? Any help at all is greatly appreciated

    This is all I have
    <html>

    <head>
    <title> Compare A Number to 20 </title>
    </head>
    <body>
    <p>Enter a number</p>
    <input type="text" id="num1" value= "" size="10" />
    <br/>
    <input type="button" id="btn" value= "Compare With 20" onClick=" ? " />
    <br/>
    <input type="text" id="btn" size="10" />
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This should do it:
    Code:
    <script type="text/javascript">
    var check = function(el, change){
      if (parseFloat(document.getElementById(el).value) == 20){
        document.getElementById(change).innerHTML = '=';
      } else if(parseFloat(document.getElementById(el).value) > 20) {
        document.getElementById(change).innerHTML = '<';
      } else {
          document.getElementById(change).innerHTML = '>';
      }
    }
    </script>
    20 <span id="symbol">></span> <input type="text" size="1" value="0" id="check"/> <input type="button" onclick="check('check', 'symbol')" value="Check"/>
    Last edited by Nile; 03-31-2010 at 02:43 AM.
    Jeremy | jfein.net

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
  •