Jul 25, 2008

Multiple Drop Down Menus W/ Submit Button

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > HTML, XML etc..

free web hosting

Multiple Drop Down Menus W/ Submit Button

kvarnerexpress
I am building a page that will have 2 drop down menus and a submit button. The first menu will have one set of options, say colors (red, blue, green, yellow). The second menu will have another set of options, say sizes (small, medium, large). What I want to be able do is select a color and a size, click submit and have it go to the page for those options. So if a user picks 'Red' and 'Small' and clicks submit they will be linked to page1.html. If they pick 'Blue' and 'Large', they will be linked to page2.html, and so on.

Any ideas how to do this? Will I need to use javascript?

PS: This page is not using a database.

Thanks in advance...

Reply

sportytalk
Hmmmm, the best way to do this would be to combine php with some aspects of html, which is still possible without the need of connecting to a database and whatnot.

The following code is an example of how it could be done.

CODE

<?php
if(isset($_POST['post'])) {
if (($_POST['color'] == 'red') AND ($_POST['size'] == 'small')) {
header("Location: page1.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'small')) {
header("Location: page2.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'small')) {
header("Location: page3.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'small')) {
header("Location: page4.html"); }
elseif (($_POST['color'] == 'red') AND ($_POST['size'] == 'medium')) {
header("Location: page5.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'medium')) {
header("Location: page6.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'medium')) {
header("Location: page7.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'medium')) {
header("Location: page8.html"); }
elseif (($_POST['color'] == 'red') AND ($_POST['size'] == 'large')) {
header("Location: page9.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'large')) {
header("Location: page10.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'large')) {
header("Location: page11.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'large')) {
header("Location: page12.html"); }
else { die("Error"); }
exit;
}
?>
<form method='post' action='yourfile.php'>
<select name="color" size="1"><option>red</option><option>blue</option><option>green</option><option>yellow</option></select>
<br>
<select name="size" size="1"><option>small</option><option>medium</option><option>large</option></select>
<br>
<input type='submit' name='post' value='Press here to view the relevant page'>
</form>


The isset function is used to work out whether or not the form (html down the bottom) has had its submit button pressed.

After the isset, I've added some elseif statements. These specify the output pages for the various outcomes, the else statement is just an addition to produce errors if some mistake happens, which shouldn't.

The html at the end of the php, is the simple drop down box code, the name tag is the name which the php post variable uses on the if/else statements.

Hope this helps. There shouldn't be any problems with this coding here, as I typed onto the reply box, as opposed to my php IDE with syntax colouring! However, the testing was ok here.
If for any reason, there are bugs or problems, please don't hesitate to reply or contact me! smile.gif

 

 

 


Reply

Tyssen
Sportytalk's example could be improved further by using a switch/case statement instead of all the if elses.

Reply

methane
QUOTE(sportytalk @ Feb 16 2006, 07:31 AM) *

Hmmmm, the best way to do this would be to combine php with some aspects of html, which is still possible without the need of connecting to a database and whatnot.

The following code is an example of how it could be done.

CODE

<?php
if(isset($_POST['post'])) {
if (($_POST['color'] == 'red') AND ($_POST['size'] == 'small')) {
header("Location: page1.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'small')) {
header("Location: page2.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'small')) {
header("Location: page3.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'small')) {
header("Location: page4.html"); }
elseif (($_POST['color'] == 'red') AND ($_POST['size'] == 'medium')) {
header("Location: page5.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'medium')) {
header("Location: page6.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'medium')) {
header("Location: page7.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'medium')) {
header("Location: page8.html"); }
elseif (($_POST['color'] == 'red') AND ($_POST['size'] == 'large')) {
header("Location: page9.html"); }
elseif (($_POST['color'] == 'blue') AND ($_POST['size'] == 'large')) {
header("Location: page10.html"); }
elseif (($_POST['color'] == 'green') AND ($_POST['size'] == 'large')) {
header("Location: page11.html"); }
elseif (($_POST['color'] == 'yellow') AND ($_POST['size'] == 'large')) {
header("Location: page12.html"); }
else { die("Error"); }
exit;
}
?>
<form method='post' action='yourfile.php'>
<select name="color" size="1"><option>red</option><option>blue</option><option>green</option><option>yellow</option></select>
<br>
<select name="size" size="1"><option>small</option><option>medium</option><option>large</option></select>
<br>
<input type='submit' name='post' value='Press here to view the relevant page'>
</form>


The isset function is used to work out whether or not the form (html down the bottom) has had its submit button pressed.

After the isset, I've added some elseif statements. These specify the output pages for the various outcomes, the else statement is just an addition to produce errors if some mistake happens, which shouldn't.

The html at the end of the php, is the simple drop down box code, the name tag is the name which the php post variable uses on the if/else statements.

Hope this helps. There shouldn't be any problems with this coding here, as I typed onto the reply box, as opposed to my php IDE with syntax colouring! However, the testing was ok here.
If for any reason, there are bugs or problems, please don't hesitate to reply or contact me! smile.gif


Actually, javascript can do you need. You should write a function called by on submit form. In the javascript function you can use switch cases to check the inputs and then redirect the page to what you need it to go.

Reply

Inspiron
It can be done with just javascript. I've typed this HTML file and javascript on my own on notepad and tested it. It's working. Just change the variables in the selection tags <select> to suit your desire. Add another <select> tag to make a second dropdown menu.

This code is an entire HTML file. Simply copy the all its contents and paste it in notepad and save as a HTML file.

CODE

<html>
<head>
  <title> My Page </title>
  
  <script language="javascript">
  
   function checkSelected()
   {
      if (document.myForm.selection.value == "page1")
      {
         window.location = "http://www.microsoft.com/";
      }
      if (document.myForm.selection.value == "page2")
      {
         window.location = "http://www.google.com/";
      }

      if (document.myForm.selection.value == "page3")
      {
         window.location = "http://www.getfirefox.com/";
      }
   }
  
  </script>
</head>

<body>
<form name="myForm" onsubmit="">
  <select size="1" name="selection">
   <option value="page1"> Page 1  (www.microsoft.com) </option>
   <option value="page2"> Page 2  (www.google.com)</option>
   <option value="page3"> Page 3  (www.getFireFox.com) </option>
  </select>
  <input type="button" name="submit" value="Go !" onclick="checkSelected();">
</form>
</body>

</html>


Phew.. Took me 15 minutes to figure out this... Pretty simple logic.. wink.gif

Reply

nelarozi
use a program like 1 Cool Menu FX Tool! this program is payable but perfect for biginners wink.gif

Reply

iGuest
Replying to methane

I'd go with the PHP and not the javascript, simply because if someone has javascript disabled on their browser (as many people do these days, thanks to your friendly neighbourhood spyware authors), it'll fail miserably.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. html drop down list with a submit button - 1.49 hr back. (1)
  2. html form reset drop down - 4.30 hr back. (1)
  3. html drop down submit button - 5.43 hr back. (1)
  4. php drop down option event - 7.07 hr back. (1)
  5. php form dropdown multiple varaible - 8.92 hr back. (1)
  6. multiple select submit php html javascript - 9.68 hr back. (1)
  7. how to link multiple drop down in php - 11.30 hr back. (1)
  8. jsp form drop down multiple values - 11.72 hr back. (1)
  9. submit button with if statement - 12.34 hr back. (1)
  10. form button drop menus - 12.36 hr back. (1)
  11. dynamic create drop down menu in javascript with select radio button - 12.61 hr back. (1)
  12. how do i make a submit button in php - 12.95 hr back. (1)
  13. button location in html - 13.14 hr back. (1)
  14. jsp hit enter correct submit should submit - 13.93 hr back. (1)
Similar Topics

Keywords : multiple, drop, menus, w, submit, button

  1. Question About Multiple Voting Post Or Get Methods
    Multiple voting post or get methods on 1 page (3)
  2. About Submit Form Box
    (8)
    I make the form tags like this: CODE <form action="check.php"
    method="post"> <table>   <tr>    <td>Username:</td>
       <td><input type="text" name="user"></td> </tr>
      <tr>    <td><input type="submit" value="set"></td>
    </tr> </table> </form> my question: in the tags above, it will produce
    a submit box, right? I want to make just text: "set" that one can click it, then link it to the fo....
  3. Dynamic Button Size
    (1)
    In my application I have a custom tag that generates all the action buttons that the page needs. My
    problem is that in IE the space between the left side of the button and the image inside the button
    are not consistant. Some buttons have 3 or 4 more pixels of padding on the left side then others.
    This causes my buttons to be too large and hence the area the buttons are generated in stretches too
    far. I could wrap the buttons around to another line or add scroll bars.. but if it will fit in FF I
    think it should fit in IE as well. So my question is can I set the padding....
  4. Xhtml Strict Method For Submit/reset Buttons As An
    (1)
    What's the proper way to handle submit and reset buttons? Using type submit and reset don't
    allow you to replace the default button with an image, using the type image doesn't allow a
    button to automatically act like a submit or reset....so far as I know. So How should I do this
    when I want to use a custom image as the button? Code will be best way to explain, thanks! ....
  5. Refresh Page After Back Button Hit
    (11)
    Hi. I have a page that is dynamically build through DOM manipulation. So, when I browse outside the
    page, and then click back, those dynamically created DOM objects are gone. Since I am also using JSP
    / Servlet technology, I can rebuild this page easily, which I have done. Here is my dilemma. If
    the user leaves the dynamic page, then clicks back on their browser, I need the page they are going
    back to to refresh. I can't figure out how to do this. I've tried using the META tag, but it
    won't do it. Help would be appreciated. Thanks. ....
  6. Closing Multiple Windows
    (3)
    have a main page that comes up with several options. If you click an option, it will open another
    window. If you click on on a URL it will open another window that will allow you to select a
    quantity, etc. When you click ok to submit the form, I need to not only close the top (3rd) window
    but also the second window. I have tried every .close I can think of but can't get the second
    window closed. The top (3rd) closes fine. I have referenced the second window by name but still no
    luck. Any suggestions? ....
  7. Submit Button
    (3)
    I have a form on my page. I do not have a submit button, but when I hit enter on my text field, it
    is like I am clicking on a submit button. My page refreshes to the original state, and my values are
    reset. I found this out because I made a submit button and tried it. Is there a way to get around
    this? I am trying to use a javascript that captures the key strokes. That works, but then the submit
    like event still fires after my code runs, nullifying any changes my code has made. html4strict
    Code: CODE 1.      <form name="FormPictureInfo">   2.....
  8. Dropdown Menus Links
    IDK how to make them link (3)
    Ok its a big problem to me, i need to make my drop down menus options link to a web page. I know i
    can do it with a button, and i can get that to work but i need/want to have it link as soon as the
    option is selected........How do i do that?....
  9. Radio Button
    (4)
    I am trying to maintain the radio button selection on a Submit, but the form refreshes to its
    default selection. BTW, After a Submit is clicked, the radio form stays visible on the top of the
    screen while the query results are displayed on the bottom half of the screen (we're using an
    internal, embedded link). That's when the default selection comes into place. Any help would be
    appreciated. Please respond Kvarnerexpress.....
  10. Substitute Form Button For An Image
    homemade images in forms buttons (3)
    Hi, I have the next formular : CODE  <form method='post'
    action='index.php?mode=2&id=1'>                <input type='hidden'
    name='name' value='Canon Digital Ixus 700'/>                <input
    type='hidden' name='id' value='1'/>                <input
    type='hidden' name='qty' value='1'>                <input
    type='hidden' name='cost' value='40'>                <input
    type='submit' value='Add to ca....
  11. Button To Print Current Web Page
    (13)
    Hi, Does anyone know how to create a button that will printo out the current page. What I want to
    do is have the user fill out a form (containing name, address, zip, etc). They will then click on a
    "print" button and it will print out the form data. Any ideas? Thanks.....
  12. Enter Keypress Submits Wrong Button
    (2)
    Ive got a form, with a submit button on the left and a submit button on the right. By default on the
    enter keypress, the form submits the left submit button, but i want it to submit the right button.
    How would i accomplish this? kvarnerexpress....
  13. Insert Into Database
    Radio Buttons and dropdown menus (8)
    I am currently working on a registration page but I can't figure out a few things, wich all
    basically have the same thing in common Radio Button: In the registration form i have a gender
    selection and I want to input that into the database, I currently have the following: CODE
    <input type="radio" name="gender" value="1">Male <input
    type="radio" name="gender" value="2">Female In the registering file
    I put the following (edited for the question): CODE $SQL = "INSERT into go_logintable....
  14. need help with drop down menus!!
    (17)
    can any1 help me give a simple solution about mamking drop down menus with any programs or simple
    html coding. i want my site to look better than my friends ones but basic things like this are
    difficult for noobs like me to overcome....

    1. Looking for multiple, drop, menus, w, submit, button

Searching Video's for multiple, drop, menus, w, submit, button
advertisement



Multiple Drop Down Menus W/ Submit Button



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE