Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  146] [ 3]  / answers: 1 / hits: 59036  / 12 Years ago, wed, september 5, 2012, 12:00:00

I want to change the value of an input field whenever the value of another one is changed.



I've tried for a while and I can't seem to get it to work



<input class=span4 input-big id=dare_price name=price size=30 type=text onChange=updatePrice() />
<input class=span4 input-big id=total_price_amount readonly=readonly value=/>​


function updatePrice() {
var price = $(#dare_price).val();
var total = (price + 1) * 1.05;
$($total_price_amount).val(total);
}​


Here's the fiddle.


More From » jquery

 Answers
21
$(#dare_price).change(function(){
var total = Number($this).val()) + ...;
$('#total_price').val(total);
});


If you programatically change the values, you need to pipeline them through your method -



function changePrice(value){
$('#dare_price').val(value);
$('#dare_price').trigger('change');
}


Updated DEMO for this event-driven approach.


[#83229] Tuesday, September 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonathoncamrynv

Total Points: 339
Total Questions: 98
Total Answers: 98

Location: Saint Vincent and the Grenadines
Member since Thu, Oct 15, 2020
4 Years ago
;