Forgive me but I\’m just starting to learn Javascript. I\’m trying to get the sum of two input fields, and I\’d like to update the result \”live\” so to speak, on every keyup event.
At the moment the result field just disappears when values are entered into the input fields.
What am I doing wrong?
Thank you so much,
Peter
edit: how stupid of me, I forgot to post the code
var inputFirst = $(\'#first\'),
inputSecond = $(\'#second\'),
inputFirstVal = inputFirst.val(),
inputSecondVal = inputSecond.val();
function getResult(first, second) {
var result = first + second;
$(\'p#result\').text(result);
};
inputFirst.on(\'keyup\', function() {
getResult(inputFirstVal, inputSecondVal);
});
inputSecond.on(\'keyup\', function() {
getResult(inputFirstVal, inputSecondVal);
});





Rating:
The post javascript – Comparing two input fields – What am I doing wrong? appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-comparing-two-input-fields-what-am-i-doing-wrong.html
No comments:
Post a Comment