wangtian Posted March 31, 2011 Share Posted March 31, 2011 someone can help me on this code? I appreicate it. I want to calculate the dropdown boxs values. the values that on the dropdown box are retrived from the mysql database. I want to have total price on the page without refresh. maybe you will be eassier to understand I am trying to say if you see my attached UI picture. here are the code; <code> <html> <head> <title> </title> <script type="text/javascript"> $('document').ready( function() { function change() { var quantity = $('#quantity').val(); var chassis = $('#chassis').val(); var sum = quantity * chassis; $('#the_sum').val(sum); } }); </script> </head> <body> <form action="" method="post"> <?php mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("a4202648_wang") or die(mysql_error()); 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 id="chassis" 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" value=',$row['Chassis_Price'],'>',$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 id="quantity" 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 value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> <input type="text" value="" id="the_sum" /> <input type="submit" /> </form> </body> </html> </code> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/232325-calculate-the-value-in-two-dropdown-box-without-refresh/ Share on other sites More sharing options...
ManiacDan Posted March 31, 2011 Share Posted March 31, 2011 You have to use javascript to do calculations without page refreshes. javascript is a language that exists inside your HTML document and is executed on the client's computer, not on your server. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/232325-calculate-the-value-in-two-dropdown-box-without-refresh/#findComment-1195188 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.