As a beginner for javascript, I’m having some difficulties to build functions so that multiple functions use the same element on a page. The purpose of the function is to calculate and display a value based on the input of a user.
The function looks like this:
<script language='javascript' type='text/javascript'>
document.getElementById("n182849949").onblur= function() {
reSumText1();
}
document.getElementById("n182849950").onblur= function() {
reSumText1();
}
document.getElementById("n182849951").onblur= function() {
reSumText1();
}
document.getElementById("n182849952").onblur= function() {
reSumText1();
}
function Tonumber(numX) {
return Number(numX.replace(".","").replace(" ","").replace(",","."))
}
function reSumText1() {
var num1 = Tonumber(document.getElementById("n182849949").value);
var num2 = Tonumber(document.getElementById("n182849950").value);
var num3 = Tonumber(document.getElementById("n182849951").value);
var num4 = Tonumber(document.getElementById("n182849952").value);
var sum2 = num1 + num2 + num3 + num4;
var sum3 = sum2.toLocaleString('de-DE');
document.getElementById("1").innerHTML =sum3;
}
</script>
The function works fine, but as soon as two functions use the same element (e. g. “n182849952”) only the last one mentioned will work. How can this be solved?
Thanks a lot in advance!