Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  71] [ 2]  / answers: 1 / hits: 6218  / 11 Years ago, sat, january 4, 2014, 12:00:00

I have these two input boxes here.



<input type=text name=ltc>
<input type=text name=btc readonly>


Ok, now what I want is..that when I enter some value in the first textbox, then that value would be multiplied by a constant number and the result would be displayed in the btc textbox.



I guess this can be done via jQuery, but I have no idea as to how I can do it(because of my limited/no knowledge in jQuery).
Can somebody guide me?



Thanks.


More From » jquery

 Answers
2

Quick solution:



html code:



<input type=text name=ltc id=input-ltc>
<input type=text name=btc readonly id=input-btc>


javascript:



var inputLtc = document.getElementById('input-ltc'),
inputBtc = document.getElementById('input-btc');

var constantNumber = 2;

inputLtc.onchange = function() {
var result = parseFloat(inputLtc.value) * constantNumber;
inputBtc.value = !isNaN(result) ? result : '';
};


jsfiddle: http://jsfiddle.net/6KT4R/



edit:



You may use onkeydown to get result when typing.


[#48991] Friday, January 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brennanm

Total Points: 510
Total Questions: 103
Total Answers: 95

Location: Nicaragua
Member since Tue, Dec 8, 2020
4 Years ago
brennanm questions
Thu, Jan 9, 20, 00:00, 5 Years ago
Thu, Sep 26, 19, 00:00, 5 Years ago
Thu, Aug 29, 19, 00:00, 5 Years ago
;