I am having a problem with a simple script that is supposed to update a page with some values(user input) that are turned from monthly to yearly (the numbers go into numeric fields created by confirmIT)
<script>
function update() {
for (var i = 0; i < 9; i++) {
var ans = parseInt(document.getElementById("bq10a_" + i).value, 10);
if (!isNaN(ans)) {
var new = ans * 12;
document.getElementById("bq10a_" + i + "calc").value = new;
}
}
}
return;
}
setInterval("update()", 1000);
</script>
this yields an Expected identifier error on line
var new = ans*12;
and i would appreciate any help on how to solve it
The word
newis a reserved word in JavaScript and cannot be used as the name of a variable.The error means that the parser expected an “identifier”, which is to say that it expected to see a valid identifier.
Change the name of the variable and things should improve. In the code you’ve posted I think there’s a
{ }nesting problem; there appears to be one too many before thereturnof the function.edit — also as jbabey notes in a comment, your
setInterval()call should beIt’s not a good idea, generally, to pass strings to
setInterval(), despite the advice of thousands of mouldy old instructional websites.