Jump to content

performing math on selections made from a drop down box


flipper828

Recommended Posts

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";


?>

]

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";


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.