Javascript

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux