javascript - Add value of button into input field on button click -


as new javascript. want make calculator, stuck on getting button value field. suppose have following button

<input id='add' type='button' onclick='ik();'  value='1'> 

and following field

<input type='text' id='one' class='fld'> 

hope i'll clear replies...

you can customize in anyway want.

function ik(val){  document.getelementbyid('one').value = val;    }
<input id='add' type='button' onclick='ik(this.value);'  value='1'>  <input type='text' id='one' class='fld'>

and, if want add current value:

function ik(val){     result = document.getelementbyid('one');     result.value = result.value? parseint(result.value) + parseint(val) : parseint(val);    }
<input id='add' type='button' onclick='ik(this.value);'  value='1'>  <input type='text' id='one' class='fld'>


Comments