?
Solved

drop down boxes and forms

Posted on 2012-04-04
12
Medium Priority
?
240 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 800 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 800 total points
ID: 37809106
that's what I thought,
You have to name the <select> element, like I said.
0
Industry Leaders: 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!

 
LVL 4

Assisted Solution

by:TechHelpr08210
TechHelpr08210 earned 1200 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 111

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 111

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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?
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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 …
Suggested Courses

777 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