Skip to main content
Inspiring
May 14, 2007
Answered

Auto fill field...

  • May 14, 2007
  • 3 replies
  • 446 views
I have a form which collects some currency value data.

what I am trying to achieve is to obtain a calculated value, based on the above, which would then appear in another text field automatically before submit. This value would then be saved to the db on submit.

for instance:

<?php
$unitvalue=$POST_VARS['textfieldunitvalue'];
$quantity=$POST_VARS['textfieldquantity'];
$totalvalue=($unitvalue*$quantity);
?>
<td><input name="textfieldtotalvalue" type="text" id="textfieldtotalvalue" value=$totalvalue></td>

I assume though that both the GET and POST methods only activate on "sumbit"

How then do I achieve an autofill functionality?

Is there a simpler solution?
This topic has been closed for replies.
Correct answer Newsgroup_User
On 14 May 2007 in macromedia.dreamweaver.appdev, geschenk wrote:

> youïre approach is correct, but youïll need to enclose the text
> fieldïs value in <?php ... ?> and in here "echo" the variable,
> means:
>
> <td><input name="textfieldtotalvalue" type="text" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>"></td>
>
> The way it ïs now, the visitor would be able to change or erase the
> fieldïs contents, so if you donït want this to happen, you should
> better make this a hidden field, means...
>
> <input type="hidden" name="textfieldtotalvalue" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>">
>
>
> ...and additionally "echo" the result as plain text

Actually, since this is a derived value, it shouldn't be stored in the
database at all; it should be calculated when the value comes out of
the database. At a minimum, the calculation should be done
serverside, just before inserting it. Any time you create the value
by calculating clientside, some enterprising site visitor could create
their own form to submit this information.

You can display the information in unchangable form like this; note
the 'disabled' attribute:

<input
name="textfieldtotalvalue"
type="text"
id="textfieldtotalvalue"
value="<?php echo $totalvalue; ?>"
disabled="disabled">

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

3 replies

Inspiring
May 14, 2007
I should have thought of this before!

Many thanks for your comments.
Newsgroup_UserCorrect answer
Inspiring
May 14, 2007
On 14 May 2007 in macromedia.dreamweaver.appdev, geschenk wrote:

> youïre approach is correct, but youïll need to enclose the text
> fieldïs value in <?php ... ?> and in here "echo" the variable,
> means:
>
> <td><input name="textfieldtotalvalue" type="text" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>"></td>
>
> The way it ïs now, the visitor would be able to change or erase the
> fieldïs contents, so if you donït want this to happen, you should
> better make this a hidden field, means...
>
> <input type="hidden" name="textfieldtotalvalue" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>">
>
>
> ...and additionally "echo" the result as plain text

Actually, since this is a derived value, it shouldn't be stored in the
database at all; it should be calculated when the value comes out of
the database. At a minimum, the calculation should be done
serverside, just before inserting it. Any time you create the value
by calculating clientside, some enterprising site visitor could create
their own form to submit this information.

You can display the information in unchangable form like this; note
the 'disabled' attribute:

<input
name="textfieldtotalvalue"
type="text"
id="textfieldtotalvalue"
value="<?php echo $totalvalue; ?>"
disabled="disabled">

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php
Günter_Schenk
Inspiring
May 14, 2007
Hi,

you´re approach is correct, but you´ll need to enclose the text field´s value in <?php ... ?> and in here "echo" the variable, means:

<td><input name="textfieldtotalvalue" type="text" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>"></td>

The way it´s now, the visitor would be able to change or erase the field´s contents, so if you don´t want this to happen, you should better make this a hidden field, means...

<input type="hidden" name="textfieldtotalvalue" id="textfieldtotalvalue" value="<?php echo $totalvalue; ?>">


...and additionally "echo" the result as plain text