Thursday, July 30, 2015

Multiply two values without clicking a button - Jquery

Multiplies both the text input numbers and shows the result in the third box .
User can enter a value in the 2nd text box so it automatically multiplies and shows the result in the 3rd textbox without any button.

HTML CODE:

<input type="text" name="input1" id="input1" value="5">
<input type="text" name="input2" id="input2" value="">
<input type="text" name="output" id="output" value="">

Script:
<script>
$(function(){
   $("#input2,#input1").keyup(function () {

    $('#output').val($('#input1').val() * $('#input2').val());

  });
}); 
</script>

OUTPUT:

http://jsfiddle.net/sarathsprakash/YFgkB/10/


1 comment: