Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  21] [ 6]  / answers: 1 / hits: 17789  / 11 Years ago, thu, october 24, 2013, 12:00:00

I know this is an extremely basic question but I'm stuck on this.
I have two input boxes and I want to calculate those inputs and show the result into another input (3rd one) immediately without the need of a submit button.
I means, once I start entering the values into the input and the result will shows live in the 3rd input which is the represent the result...



<input type=text class=input value1>
<input type=text class=input value2>
<input type=text disabled=disabled id=result>

<script>
$(document).ready(function(){
var val1 = $(.value1).val();
var val2 = $(.value2).val();
$(.input).keyup(function(){
$(#result).text(val1+val2);
});
});
</script>

More From » jquery

 Answers
34

Put val1 and val2 in keyup statement.



$(document).ready(function(){
$(.input).keyup(function(){
var val1 = +$(.value1).val();
var val2 = +$(.value2).val();
$(#result).val(val1+val2);
});
});


Look at fiddle: http://jsfiddle.net/g7zz6/


[#74757] Wednesday, October 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;