Solved

drop down boxes and forms

Posted on 2012-04-04
12
231 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 108

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 108

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now