Click to See Complete Forum and Search --> : I just cant get my head around setting form value


ICEcoffee
07-02-2004, 02:09 PM
Hi all

I've spent so much time trying to set these form values, it's getting silly not to mention frustrating. Here is what I am trying to do, (see code below):

A form is presented with a table partially completed, taking values stored in a database. The field I am interested in is "Price". Whether the user chages this value or not is not the issue (I think). What I'm tring to do is to set 2 hidden fields with values based on the value of "price".

I was told on a previous thread, the "value" option within the <input> tag, is text only and cant contain a call to a funtion. so how do I set the values of the fields called Vat and PriceMinusVat? I want do do some math on the Value of "Price" to get the values for the other 2 fields.

Please help whilst I still have hair.

====================================

<input name="Price" type="text" id="price" style="height:20px; font-family:Arial,Tahoma; font-size:11px " value="<?php echo $row_RSparts['Price']; ?>" size="10" maxlength="10">
<td height="18" colspan="2"><input type="submit" name="Submit4" value="Submit">
<input name="Callid" type="hidden" id="Callid43" value="<?php echo $HTTP_GET_VARS['Callid']; ?>">
<input name="ID" type="hidden" id="ID"> <br> </td>
<td height="18"><input name="PartPageNum" type="hidden" id="PartPageNum" value="<?php echo $row_RSpartpagenum['PageNum'] +1; ?>">
<input name="VAT" type="hidden" id="VAT" value="">
<input name="PriceMinusVAT" type="hidden" id="PriceMinusVAT" value=""></td>

=======================================

Kor
07-03-2004, 02:18 AM
[/quote]
I want do do some math on the Value of "Price" to get the values for the other 2 fields.
[/quote]

The text value is a string not a number (nomatter if it is initially set or input by user). Thus to operate math with these values you have to parse them into integer using parseInt() or Number() methods.

ICEcoffee
07-03-2004, 04:50 AM
I don't understand, what do you mean and will this solve the problem?:mad:

Fang
07-03-2004, 06:06 AM
<input name="Price" type="text" id="price" value="<?php echo $row_RSparts['Price']; ?>" size="10" maxlength="10" onchange="DoSomeMaths();">

Kor
07-05-2004, 02:09 AM
Fang is also right:

1. you need an event handler to fire a function, thus he suggest "onchange"

2. The input's value is a string. Thus if you take it as a variable

var v= document.forms[0].inputname.value, where let's say user input : "7"

and try, for instance, to add a number

var sum=v+3;

The result will be 73 (concatenate two strings) not 10, as you intended to do as a math operator.

Thus you need something like

var v= parseInt(forms[0].inputname.value)

to be sure that your value will be treated as number, not as string