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


?>

]

Link to comment
Share on other sites

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


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.