Solved

drop down boxes and forms

Posted on 2012-04-04
12
236 Views
Last Modified: 2012-07-10
What do I need to change to get this code to work?

page1.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
 <form action="welcomeCar.php" method="post">
   <select>
    <option value="volvo" name"1">Volvo</option>
    <option value="saab" name="2">Saab</option>
    <option value="mercedes"name="3">Mercedes</option>
    <option value="audi" name="4">Audi</option>
   </select>

   <select>
    <option value="volvo" name="5">Volvo</option>
    <option value="saab" name="6">Saab</option>
    <option value="mercedes" name="7">Mercedes</option>
    <option value="audi" name="8">Audi</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>

Open in new window


welcomeCar.php

Welcome <?php echo $_POST["1"]; ?>!<br />
Welcome <?php echo $_POST["2"]; ?>!<br />
Welcome <?php echo $_POST["3"]; ?>!<br />

Open in new window

0
Comment
Question by:NewWebDesigner
  • 2
  • 2
  • 2
  • +2
12 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 200 total points
ID: 37808865
???
what do you want to happen?
Please articulate a proper question.

(I guess you might want to name the select, not the options like this:

<select name="1">

...but I'm just guessing)
0
 

Author Comment

by:NewWebDesigner
ID: 37808903
Sorry for the unclear question.  This is what I want to happen: A user selects an option from each drop down box. When they click submit, the choices are submitted to the welcomeCar.php page where the choices the user made are printed.  the wecomeCar.php code should be:

Welcome <?php echo $_POST["1"]; ?>!<br />
Welcome <?php echo $_POST["2"]; ?>!<br />

Open in new window

0
 
LVL 7

Assisted Solution

by:designatedinitializer
designatedinitializer earned 200 total points
ID: 37809106
that's what I thought,
You have to name the <select> element, like I said.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Assisted Solution

by:TechHelpr08210
TechHelpr08210 earned 300 total points
ID: 37809262
Here you go...

This is corrected and should run now for whatever your trying to do.

Page1.html - Corrected

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page 1</title>
</head>

<body>
 <form action="welcomeCar.php" method="post">
   <select name="car1">
    <option value="volvo" name"1">Volvo</option>
    <option value="saab" name="2">Saab</option>
    <option value="mercedes"name="3">Mercedes</option>
    <option value="audi" name="4">Audi</option>
   </select>

   <select name="car2">
    <option value="volvo" name="5">Volvo</option>
    <option value="saab" name="6">Saab</option>
    <option value="mercedes" name="7">Mercedes</option>
    <option value="audi" name="8">Audi</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>
 

Open in new window




welcomeCar.php - Corrected

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>welcomeCar.php</title>
</head>

<body>
Welcome <?php echo $_POST["car1"]; ?>!<br />
Welcome <?php echo $_POST["car2"]; ?>!<br />

</body>
</html>

Open in new window

0
 
LVL 7

Expert Comment

by:Atique Ansari
ID: 37809541
Please find the attached files.

Let me know if you need more help.

Page1.html

welcomeCar.php
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37809902
This looks a lot like another question I've see this morning.  Everybody must be doing the same exercise ;-)

Unnamed input tags are simply absent from the request.  If you want to see the client input, you must give the <input> or <select> tags a name attribute.  I'll show you a code example in a moment...
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37809936
This is a typical design pattern for drop-down select lists.  A NULL choice is offered and the client is asked to choose from a list.  You can try running this on my server to see what happens.  Please see:
http://www.laprbass.com/RAY_temp_newwebdesigner.php
<?php // RAY_temp_newwebdesigner.php
error_reporting(E_ALL);

if (!empty($_POST))
{
    // SHOW THE CONTENTS OF THE POST ARRAY
    echo "<pre>";
    var_dump($_POST);
    echo "</pre>";
    echo PHP_EOL;
}

// CREATE THE HTML USING HEREDOC NOTATION
$html = <<<HTML
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="iso-8859-1" />
<title>Form Demonstration</title>
</head>

<body>
 <form method="post">
   <select name="CAR_ONE">
    <option value="" selected>Please Choose A Car</option>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>

   <select name="CAR_TWO">
    <option value="" selected>Please Choose Another Car</option>
    <option value="ford" >Ford</option>
    <option value="chevrolet" >Chevy</option>
    <option value="chrysler" >Chrysler</option>
    <option value="bmw" >Bimmer</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>
HTML;

echo $html;

Open in new window

0
 
LVL 4

Expert Comment

by:TechHelpr08210
ID: 38156467
Agreed, that sounds like a fine solution to me as well.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question