html - Three things I don't understand about this javascript calculator -


hey i'm new javascript , wondering bit of code never saw , wondering how worked practice javascript wanted make calculator , got code online wondering 3 things.

  1. how code know output number , answer text box.

  2. how line of code work? calc.input.value know calc form input input , value value of input 1 2 or 3 how in know input i'm choosing?

  3. what calc.input.value = eval(calc.input.value) , how work?

thanks time , have nice day , sorry if didn't give enough info.

<form name="calc"> <table border=4> <tr> <td> <input type="text"   name="input" size="16"> <br> </td> </tr> <tr> <td> <input type="button" name="one"   value="  1  " onclick="calc.input.value += '1'"> <input type="button" name="two"   value="  2  " onclick="calc.input.value += '2'"> <input type="button" name="three" value="  3  " onclick="calc.input.value += '3'"> <input type="button" name="plus"  value="  +  " onclick="calc.input.value += ' + '"> <br> <input type="button" name="four"  value="  4  " onclick="calc.input.value += '4'"> <input type="button" name="five"  value="  5  " onclick="calc.input.value += '5'"> <input type="button" name="six"   value="  6  " onclick="calc.input.value += '6'"> <input type="button" name="minus" value="  -  " onclick="calc.input.value += ' - '"> <br> <input type="button" name="seven" value="  7  " onclick="calc.input.value += '7'"> <input type="button" name="eight" value="  8  " onclick="calc.input.value += '8'"> <input type="button" name="nine"  value="  9  " onclick="calc.input.value += '9'"> <input type="button" name="times" value="  x  " onclick="calc.input.value += ' * '"> <br> <input type="button" name="clear" value="  c  " onclick="calc.input.value = ''"> <input type="button" name="zero"  value="  0  " onclick="calc.input.value += '0'"> <input type="button" name="doit"  value="  =  " onclick="calc.input.value = eval(calc.input.value)"> <input type="button" name="div"   value="  /  " onclick="calc.input.value += ' / '"> <br> </td> </tr> </table> </form>  

  1. see onclick attribute: if it's clicked, execute code in onclick. actual value of input modified these += (append to). (if current input 6 + , click 4, 4 appended: 6 + 4)
  2. input here equivalent name attribute of first input, that's why it's chosen.
  3. eval(calc.input.value) interpreting value of input javascript. when there 4 + 6 in input, it'll evaluated javascript , return 10.

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -