RE: Javascript

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

 



The reason for this is these fields are regarded as text and unless you
specify number(variable) it may treat it as text.. When
Field1='0'
Field2='1'
Field3='2'

Field1+Field2+Field3 = '012'

If you use 
Field1=Number('0')
Field2=Number('1')
Field3=Number('2')

Field1+field2+field3 = 3

Cheers
Simon

-----Original Message-----
From: Ignatius Reilly [mailto:ignatius.reilly@free.fr] 
Sent: 11 October 2002 15:48
To: Shahmat Dahlan; php-db@lists.php.net
Subject: Re:  Javascript


I have met this problem before.

The only solution I have found is to assign "0" values to the INPUT tags:
<input type="text" name="field1" addChange="add();" value="0">

HTH
Ignatius
____________________________________________
----- Original Message ----- 
From: "Shahmat Dahlan" <shahmatd@sains.com.my>
To: <php-db@lists.php.net>
Sent: Friday, October 11, 2002 11:34 AM
Subject:  Javascript


> 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
> 
> 


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

-- 
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