wangtian Posted March 30, 2011 Share Posted March 30, 2011 hi. I am stuck on the dropdown box value calculation. anyone can help me on this problem ? I appreciate it. I have two dropdown boxes on my webpage, and the values that in the dropdown boxes are retrived from the mysql database. dropdown box "A" displays two differnt values, which are "Chassise_Name" and "Chassise_price", and The dropdown box "B" displays the quantity of the item. Dropdown box "A" Dropdown box "B" SuperServer 7036A-T(Black) $90 3 "Superserver 7036A-T(Black)" is retrieved from the Chassis_Name ; "$90" is retrieved from the chassis_Price; "3" is retrieved from the Quantity in other table. Question: how can I take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"? Here is my code: echo "<table border='1'>"; echo "<tr><td>"; $result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select name="Chassis" onChange="change()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis">',$row['Chassis_Name'],' ',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select name="Quantity" Value="Quantity" onChange="change()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option Name="Quantity">',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/232234-how-to-multiplyor-sum-the-dropdown-box-value-that-trieved-from-mysql-database/ Share on other sites More sharing options...
requinix Posted March 31, 2011 Share Posted March 31, 2011 take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"? When? When do you want to do that? You can't do it when you're displaying the page because the user hasn't picked anything yet, so your choices are: a) When they pick something (from both dropdowns) but before they submit the form. b) When they submit the form, probably on some kind of confirmation page. Quote Link to comment https://forums.phpfreaks.com/topic/232234-how-to-multiplyor-sum-the-dropdown-box-value-that-trieved-from-mysql-database/#findComment-1194728 Share on other sites More sharing options...
wangtian Posted March 31, 2011 Author Share Posted March 31, 2011 that's true . I want to show the result of the multiply before the user submit the form, then display the invoice after sumbit the form . the problem now is I don't know how to code the calculation. Quote Link to comment https://forums.phpfreaks.com/topic/232234-how-to-multiplyor-sum-the-dropdown-box-value-that-trieved-from-mysql-database/#findComment-1194730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.