Jump to content

[SOLVED] calculate values from drop downs


eideticmnemonic

Recommended Posts

Hi. I'm probably the biggest n00b ever, so I apologize in advance for what is surely a very dumb question. :S

Fyi, I've been trying to get this to work myself all day long before posting here.

 

I want to create an order form which includes 2 drop down menus, StartLength and EndLength, the menu options for both being:

0-10 min

10-30 min

30-60 min

 

The respective values for each option are:

25

50

100

 

(the user should not see these values.) The total cost will be displayed and will be the average of the two values.

 

 

I've tried several different things, and nothing has really worked.

Here is the code I have at the moment.... I'm sure it's atrocious. :S

 

 

<?php

// initialize or capture variable

$StartLength = !isset($_POST['startLength'])? NULL : $_POST['startLength'];

?>

<select name="startLength">

<option value="25">0-10</option>

<option value="50">10-30</option>

<option value="100">30-60</option>

</select>

 

<?php

$EndLength = !isset($_POST['EndLength'])? NULL : $_POST['EndLength'];

?>

<select name="EndLength">

<option value="25">0-10</option>

<option value="50">10-30</option>

<option value="100">30-60</option>

</select>

 

<?php

$numStartLength = $_Post[startLength];

$numEndLength = $_Post[EndLength];

$numvfx = $_Post[vfx];

$totalcost = ($numStartLength + $numEndLength)/2;

?>

<BR><BR>

Your total is: <?php echo number_format($totalcost,2,'.',','); ?>.

 

 

 

Link to comment
Share on other sites

first verify you get anything in the $_POST by doing a print_r($_POST).  It looks like your form name for the start is startLength whereas you are attempting to extract data from $_Post[startLength].  See the difference, one is capitalized, this will cause a problem.

 

Basically if the data is in both $_POST elements for the start and end you should just need to those two $_POST elements together, number format them, and display to the screen.

Link to comment
Share on other sites

You need a submit button, here is some working code that I think does what you want.

 

<form method="post">
<select name="startLength">
<option value="25">0-10</option>
<option value="50">10-30</option>
<option value="100">30-60</option>
</select>

<select name="EndLength">
<option value="25">0-10</option>
<option value="50">10-30</option>
<option value="100">30-60</option>
</select>
<input type="submit" name="submit" value="Add Values!">
</form>

<?php

if(isset($_POST['submit'])){
   $start = $_POST['startLength'];
   $end = $_POST['EndLength'];
   $totalcost = ($start + $end)/2;

   echo '<BR><BR>';
   echo 'Your total is: '. number_format($totalcost,2,'.',','). '.';
}

?>

 

When you press submit it will give you the total cost.

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.