kodt
06-14-2007, 07:15 PM
I have a form with 4 text input fields. The last one is the total of the previous three fields and should automatically calculate this value when a user enters data into any of the first 3.
Normally I would put an onkeyup="" event on the input elements and have that call the function. However, this form is automatically generated based upon information in an XML file. I can add some HTML and Javascript to the page via the XML file, but cannot directly modify the form elements. I am wondering if there is a way to run the calcIT() function below on every onkeyup event. The code below does not seem to be working. I know the calcIT function works correctly.
I have also tried document.onkeyup, and I have tried creating an Alert box in the calcNow function. Neither worked.
window.onkeyup=calcNow;
function calcNow {
calcIT(document.quizform.userans0.value, document.quizform.userans1.value, document.quizform.userans2.value);
}
function calcIT(v,a,b) {
var total, v2, a2, b2;
v2 = parseFloat(v)
a2 = parseFloat(a)
b2 = parseFloat(b)
total = (v2 + a2 + b2);
document.quizform.userans3.value = total;
}
Normally I would put an onkeyup="" event on the input elements and have that call the function. However, this form is automatically generated based upon information in an XML file. I can add some HTML and Javascript to the page via the XML file, but cannot directly modify the form elements. I am wondering if there is a way to run the calcIT() function below on every onkeyup event. The code below does not seem to be working. I know the calcIT function works correctly.
I have also tried document.onkeyup, and I have tried creating an Alert box in the calcNow function. Neither worked.
window.onkeyup=calcNow;
function calcNow {
calcIT(document.quizform.userans0.value, document.quizform.userans1.value, document.quizform.userans2.value);
}
function calcIT(v,a,b) {
var total, v2, a2, b2;
v2 = parseFloat(v)
a2 = parseFloat(a)
b2 = parseFloat(b)
total = (v2 + a2 + b2);
document.quizform.userans3.value = total;
}