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. -
document.onkeyup = 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;
-
-
}
6 5237 acoder 16,027
Recognized Expert Moderator MVP
Welcome to TSDN!
Put the call to calcIt into another function, say calcNow, and then call:
Welcome to TSDN!
Put the call to calcIt into another function, say calcNow, and then call:
This does not appear to work either. Below is my updated code. I also tried putting an alert box in calcNow for testing, and it did not show up. Thanks. - 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;
-
-
}
acoder 16,027
Recognized Expert Moderator MVP
You forgot the parentheses on line 3:
You forgot the parentheses on line 3:
Thanks that worked.
I find that most of my javascript errors are syntax errors that I overlook :\
gits 5,390
Recognized Expert Moderator Expert
Thanks that worked.
I find that most of my javascript errors are syntax errors that I overlook :\
... to avoid it you may use an editor that checks such things (personally i use eclipse with the jseclipse-plugin) ... or to find that errors you may use the firebug-extension for firefox ... really good tools for js-development ...
kind regards ...
Replaced window.onkeyup with the following code to work in IE. -
window.onload = function() {
-
document.getElementById('userans0').onkeyup = calcNow;
-
document.getElementById('userans1').onkeyup = calcNow;
-
document.getElementById('userans2').onkeyup = calcNow;
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Powell |
last post by:
Relevancy scores are normally defined by a MySQL query on a table that
has a fulltext index. The rules for relevancy scoring will exclude
certain words due to their being too short (minimum...
|
by: Greg |
last post by:
I have the following code (a one line function)
I'm trying to calculate a value for text field matPerPiece# where #
is a row number I provide. The value is calculated from text fields...
|
by: Stumped and Confused |
last post by:
Hello,
I really, really, need some help here - I've spent hours trying to find a
solution.
In a nutshell, I'm trying to have a user input a value in form's
textfield. The value should then be...
|
by: engwar |
last post by:
I'd like to know if it's possible to change the contents of a div tag
based on something the user is doing.
For example. If there is a text box on a page and the user types his or
her name can I...
|
by: Lee |
last post by:
I have this function that doesn't work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn't work is that I want to add an "onkeyup" on...
| |
by: jdzemke |
last post by:
I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. ...
|
by: bonneylake |
last post by:
Hey Everyone,
Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
|
by: rubenhan |
last post by:
Hi,
I'm trying to use closure to pinpoint a form from a list of forms with the same name to erase its onblur function when the chosen form goes onblur.
For example, there will be indefinite...
|
by: sureshl |
last post by:
function cal()
{
var f = document.form1;
var regExp_Count = new RegExp("^+$");
f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0);
}
cal() functions , will...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |