Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:37:48+00:00 2026-05-31T23:37:48+00:00

I have created a populated dropdown list in HTML. When the two dropdowns have

  • 0

I have created a populated dropdown list in HTML. When the two dropdowns have been selected, the form posts to ‘calculate.php’ where the php script echoes out the selected values from the dropdowns.

<form action="calculate.php" method='POST'>
<select name="Phones">
<option value="Lumia800">Nokia Lumia 800</option>
<option value="iPhone">Apple iPhone 4s</option>
<option value="GalaxyS2">Samsung Galaxy S2</option>
<option value="Bold9900">Blackberry Bold 9900</option>
<option value="SensationXE">HTC Sensation XE</option>
<option value="XperiaS">Sony Ericsson Xperia S</option>
</select>

<select name="Network">
<option value="Orange">Orange</option>
<option value="Vodafone">Vodafone</option>
<option value="O2">O2</option>
<option value="Three">Three</option>
</select>

<input type="submit" />
</form>

In this one example, ‘calculate.php’ echoes the selected dropdown values.

<?php 
$pref=$_POST['Phones'];
$pref1=$_POST['Network'];

$Orange="5";

if ($pref1 == "Orange")
{
    $total1 = $Orange;
}

$Lumia800="10";

if ($pref == "Lumia800")
{
    $total = $Lumia800 + $Orange;
}

echo $total;

    ?>

This example output is ’15’

The aim of this example is to eventually create a simple phone package system, with this set of code adding the price of the phone, the network costs, and other variables together for a final total of how much it would cost when the user submits it.

The problem I have is that I want to add each variable from the corresponding dropdown boxes (“Phones” and “Network” for example) against each other. Is my example going to be too over complicated for such a simple script? Is there a more refined method to get the results that I want?

Thanks,

JB.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:37:49+00:00Added an answer on May 31, 2026 at 11:37 pm

    It will work but might be complicated. I would suggest changing over to a switch statement instead.

    $total = 0
    switch ($pref) {
      case "Orange":
        $total +=  5;
        break;
      case "O2":
        $total +=  8;
        break;
    }
    

    Same switch structure would be for the $pref1 or network variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created and html form which have a drop down list. This drop
I have created an html form. it consist of several drop down list for
I have created a PHP-script to update a web server that is live inside
I have got 2 drop down list in my php form. Values in the
I have several DropDownLists on a form which are dynamically populated as they move
I have a list of Payees in a drop down box on my form.
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I've created a infopath 2010 form with a connection to a SP list. This
I have been dealing with this for at least two days now. I don't
I have a 'created_date' DATETIME field which I would like to be populated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.