form select problem

Hi guys,

i have a question to ask regarding the web form which i want to do.

i have a form which there is a few column to let user to fill in. Some are text box and some are dropbox which the datat is from my database.

example :

product name, product price quantity and amount

product name and product price is where user able to select which base on my mysql database table. quantity is where user must key in and the amount is auto generate which is base on product price X quantity. so far everything is going well.

But there is a problem on my drop box selection. when i select product name, it will show which product is available to select. this is fine. but i would like my product price will be automatic shown base on the product name choose. i do not want the product price also in drop box style. what i want is when the user choose the product name, than the product price will be automatic shown in another column. after that, when user key in the quantity, the amount is automatic shown(this has been completed on previous post.) So How can i manage it?

this is the sample code in how my product name is been select…

[php]<?php

include ‘config.php’;

mysql_connect($server, $db_user, $db_pass);
mysql_select_db(‘sthmotor’);

$sql = “SELECT product_name FROM product”;
$result = mysql_query($sql);

echo “”;
while ($row = mysql_fetch_array($result)) {
echo “<option value=’” . $row[‘product_name’] . “’>” . $row[‘product_name’] . “”;

}
echo “”;

?>

[/php]

how do i automatic input product price field base on the product name been choosen?

Hi guys,

any ideas how i going to solve this problem? having bad times on it… cant find solution anywhere else…

You can add a custom attribute to your options…

http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

That contains the price, then add an onchange event to your select.

http://www.w3schools.com/tags/ev_onchange.asp

Then populate the field you want with javascript, by reading in the custom attribute.

Sponsor our Newsletter | Privacy Policy | Terms of Service