Javascript
| From: | Shahmat Dahlan | Date: | Fri, 11 Oct 2002 09:34:57 +0000 |
| Subject: | Javascript | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22337@lists.php.net to get a copy of this message | ||
My question might have anything to do with PHP but I have the following scenario:
Say I have four fields
field1 : XXXXXXXXXXXX
field2 : XXXXXXXXXXXX
field3 : XXXXXXXXXXXX
field4 : XXXXXXXXXXXX
And a total sum field, which is a total sum of the value of the expression, totalsum = field1 + field2 + field3 + field4
Total sum : XXXXXXXXXXX
You would need to use Javascript to extract the value of field1, field2, field3, field4, initiated by the Javascript onChange event.
The HTML codes should look like this:
<input type="text" name="field1" addChange="add();">
<input type="text" name="field2" addChange="add();">
<input type="text" name="field3" addChange="add();">
<input type="text" name="field4" addChange="add();">
<input type="text" name="totalsum">
So the add function snippet that I have:
function add()
{
var thisform=document.forms[0];
var field1=thisform.field1.value;
var field2=thisform.field2.value;
var field3=thisform.field3.value;
var field4=thisform.field4.value;
var totalqty=field1+field2+field3+field4;
thisform.totalsum.value=totalqty;
}
But all I got is a NaN which means Not A Number. I understand that you solve this by using the parseInt Javascript function.
But still all i get is a NaN value.
Would appreciate if someone could help me out on this.
Regards