Solved

drop down boxes and forms

Posted on 2012-04-04
12
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 110

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 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 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