2

I have a price calculator on my website. I would like jquery to pick the value on one box and send it to the other box in real time.

<form>
How much do you want to spend <input type="text" id="pricein" /><br />
This is how much you will spend<input type="text" id="priceout"/>
</form>

anybody know how this can be accomplished with jquery? This sounds like it might be easy but I'm learning it all slow but I'm learning. Thanks!

3 Answers 3

7
$("#pricein").keyup(function() {
    $("#priceout").val($("#pricein").val());
});​

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

whoops, should have refreshed the page before I posted my answer.
that was a working code but what about when the field is a read only field? How would you trigger a recalculation if a number in a field changes? for example, The calculator im using uses formulas to populate some field. for example: #option1 + #option2 = #sum. the div id ="sum" would be an html read field. How do I get it to dynamically readjust the number if it changes?
1

You need the val() function:

var price = $('#pricein').val()

and to set the value:

$('#priceout').val(newValue);

You can read the documentation here

Comments

1

use keyup

$('#pricein').bind('keyup', function() 
    { 
        $('#priceout').val($(this).val()); 
    });​

JSFIDDLE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.