Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  162] [ 1]  / answers: 1 / hits: 21148  / 11 Years ago, sat, july 27, 2013, 12:00:00

I am collecting a text area value(number in decimal ) using its id to a javascript variable, adding another variable value (number in decimal), and displaying the result in same html page



text area code:



<div class=input-resp><span><input  class=textbox id=num name=count type=text size=5 maxlength=3  value= /></span></div>


passing value to var and adding it to another var



var a = document.getElementById('num').value;
var b = 1000;
var c = parseFloat(a) + parseFloat(b);


passing var c to div id test



document.getElementById(test).innerHTML = c;


html for test id



<div id=test></div>


But here, whenever I am updating the text area with new number, the final output is not updating instantly.I have refresh the page manually to get new value. Is there anyway I update the value without a page refresh ?


More From » html

 Answers
6

If it's going to update whenever you type into the input, you need an event handler:



document.getElementById('num').onkeyup = function() {
var a = 1000 + parseFloat(this.value);
document.getElementById(test).innerHTML = a || 0;
}


FIDDLE


[#76697] Friday, July 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dawnc

Total Points: 612
Total Questions: 94
Total Answers: 98

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;