flipper828 Posted January 28, 2010 Share Posted January 28, 2010 I have two drop down selection boxes in a form in which a multiplication and then an addition operation need to be performed. I don't know what I am doing wrong because I load the page and get undefined variable. I thought the variable is defined when the user selects a number. It is a long long form so I am only attaching the piece I think is pertinent. If you need more, I will be glad to oblige. <form action="index.php" method="post" target="_self"> <b>Firm Name: </b><input type="text" size="50" name="firmname"> <br /> <br /> <b>Number of Attendees:</b> <select name="numattfull"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> Full X $495 <select name="numattpartial"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> Partial X $325 <?php $full = $numattfull * 495; $partial = $numattpartial * 325; $answer = $full + $partial; echo "<b>Total Fees:</b> $answer\n"; ?> ] Quote Link to comment https://forums.phpfreaks.com/topic/190142-performing-math-on-selections-made-from-a-drop-down-box/ Share on other sites More sharing options...
phpstuck Posted January 31, 2010 Share Posted January 31, 2010 You didn't have a way to submit the form... I changed the name on mine to test (change yours back to index) I added a form submit button and put your total math in ( ( ) ) - works great now! Hope that is what you are looking for! <form action="test.php" method="post" target="_self"> <b>Firm Name: </b><input type="text" size="50" name="firmname"> <br /> <br /> <b>Number of Attendees:</b> <select name="numattfull"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> Full X $495 <select name="numattpartial"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> Partial X $325 <INPUT type=submit value="Generate estimate now" name=B1> </form> <?php $full = $_POST["numattfull"] * 495; $partial = $_POST["numattpartial"] * 325; $answer = (($full) + ($partial)); echo "<b>Total Fees:</b> $answer\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190142-performing-math-on-selections-made-from-a-drop-down-box/#findComment-1004674 Share on other sites More sharing options...
phpstuck Posted January 31, 2010 Share Posted January 31, 2010 Looking at the answer one more time, might I suggest changing you echo line to: ECHO '<b>Total Fees: $'.number_format($answer,2).'</b>'; Quote Link to comment https://forums.phpfreaks.com/topic/190142-performing-math-on-selections-made-from-a-drop-down-box/#findComment-1004683 Share on other sites More sharing options...
flipper828 Posted February 3, 2010 Author Share Posted February 3, 2010 Thank you phpstuck. It did work and I appreciate your help! Quote Link to comment https://forums.phpfreaks.com/topic/190142-performing-math-on-selections-made-from-a-drop-down-box/#findComment-1006278 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.