View Full Version : Basic program Help with if function

03-31-2010, 01:26 AM
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

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

03-31-2010, 02:23 AM
This should do it:

<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 = '>';
20 <span id="symbol">></span> <input type="text" size="1" value="0" id="check"/> <input type="button" onclick="check('check', 'symbol')" value="Check"/>