Hyperjase Posted January 23, 2012 Share Posted January 23, 2012 Hi all, I'm trying to create a way of showing the sum total of a number of drop down boxes. The number of drop down boxes is dynamic, created by two variables - one being how many cupcakes and how many toppings are selected. It then creates drop downs for each selected topping and the value is the number of cupcakes chosen. Here is the code I have: <?php foreach ($_SESSION['topping'] as $value) { echo "<tr><td width='30%'>Topping</td><td width='50%'>$value</td><td width='20%'><select name='notopping[$value]'>"; $counter = 1; while ( $counter <= $_SESSION['cupcake'] ) { echo '<option value='.$counter.'>'.$counter.'</option>'; $counter++; } echo "</select</td></tr>"; } echo "<tr><td colspan='3' align='center'>All must add up to ".$_SESSION['cupcake']."</td></tr>"; if (count($_SESSION['swtopping']) > 0) { ?> <tr> <td colspan="3"> <br /><br />Please select how many of each type of sweetie topping you would like<br /> </td> </tr> <?php foreach ($_SESSION['swtopping'] as $value) { echo "<tr><td width='30%'>Sweetie topping</td><td width='50%'>$value</td><td width='20%'><select name='noswtopping[$value]'>"; $counter = 1; while ( $counter <= $_SESSION['cupcake'] ) { echo '<option name="noswtopping" value="'.$counter.'">'.$counter.'</option>'; $counter++; } echo "</select></td></tr>"; } echo "<tr><td colspan='3' align='center'>All must add up to ".$_SESSION['cupcake']."</td></tr>"; } ?> I want a way when each drop down is changed it updates the total number selected. Also is there a way of not allowing the submit button to be pressed until the value of all the drop down boxes match the total number of cupcakes. Is this possible? Thanks, Jason Quote Link to comment https://forums.phpfreaks.com/topic/255629-on-the-fly-sum-from-multiple-drop-down-boxes/ Share on other sites More sharing options...
spiderwell Posted January 24, 2012 Share Posted January 24, 2012 there doesnt seem to be any client side scripting? can you show us the code you have so far, what have you gotten it to do Quote Link to comment https://forums.phpfreaks.com/topic/255629-on-the-fly-sum-from-multiple-drop-down-boxes/#findComment-1310661 Share on other sites More sharing options...
Hyperjase Posted January 24, 2012 Author Share Posted January 24, 2012 I have no experience with Ajax, only php - this is something I'm look to achieve and from reading up this is the most likely way of solving it .... I just have no idea how to do it! Thanks, Jason Quote Link to comment https://forums.phpfreaks.com/topic/255629-on-the-fly-sum-from-multiple-drop-down-boxes/#findComment-1310717 Share on other sites More sharing options...
Hyperjase Posted January 24, 2012 Author Share Posted January 24, 2012 This is exactly what I need, I'm currently trying this code but it doesn't want to work, just no adding it up. http://www.mcfedries.com/javascript/ordertotals.asp When you select the drop down and a value, it automatically updates the total value. Thanks, Jason Quote Link to comment https://forums.phpfreaks.com/topic/255629-on-the-fly-sum-from-multiple-drop-down-boxes/#findComment-1310796 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.