Pradeep Kumar
Pradeep Kumar

Reputation: 41

Onchange Event in JavaScript or Jquery

Please help me. I need to change a textbox value when i give value in another textbox. see i have three text box first one is Qty another Amount and third will be a Total Amount. here i will give a value for Qty and amount. Now third textbox i mean Total amount will be appear automatically.

Please help me...

Upvotes: 2

Views: 150

Answers (3)

adeneo
adeneo

Reputation: 318352

Here's a quick example: http://jsfiddle.net/adeneo/xMjdR/3/

Upvotes: 0

mrtsherman
mrtsherman

Reputation: 39902

You use the change event to monitor your first two inputs. Then you use the val method to get and set the property values.

http://jsfiddle.net/8hunC/

$('#qty, #amount').change( function(){
    var total = $('#qty').val() * $('#amount').val();
    $('#total').val(total);
});

Upvotes: 1

Aaron
Aaron

Reputation: 5247

HTML5 has an oninput event that would serve this purpose. You'd need to use events like onfocus, onkeypress and onblur in conjunction to achieve a similar level of responsiveness in older browsers, though. Or, if it's not essential that these values be updated with every keystroke, you can simply use the onchange event to update the value whenever the user changes, then blurs the textbox.

Upvotes: 0

Related Questions