OBL
OBL

Reputation: 1357

How to update the value in one text box based on the value entered in another text box?

How do I update the value in one text box (txtInterest%) based on the value entered/changed in another text box (txtAmt)?

Upvotes: 11

Views: 41143

Answers (3)

shihabudheen
shihabudheen

Reputation: 696

One more method for implementing this

$(document).ready(function(){
      $('#txtAmt').keyup(function (){
       $('#txtInterest%').val($('#txtAmt').val())
    });
    });

Upvotes: 4

bpruitt-goddard
bpruitt-goddard

Reputation: 3324

Use jQuery's change method for updating. Using your example:

$('#txtAmt').change(function() {
  //get txtAmt value  
  var txtAmtval = $('#txtAmt').val();
  //change txtInterest% value
  $('#txtInterest%').val(txtAmtval);
});

Upvotes: 14

Jacob Relkin
Jacob Relkin

Reputation: 163228

This should work assuming txtAmt and txtInterest% are ids on your page:

$(function() {
    $('#txtAmt').change(function() {
       $('#txtInterest%').val(this.value);
    });
});

See jQuery's change event handler.

Upvotes: 4

Related Questions