Nov 22, 2009

Multiple Drop Down Menus W/ Submit Button

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > HTML, XML etc..

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...

Comment/Reply (w/o sign-up)

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

 

 

 


Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

FeedBacker
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.

Comment/Reply (w/o sign-up)

iGuest-priyanka
regarding the validation of the drop down box
Multiple Drop Down Menus W/ Submit Button

I m trying to validate a form having fields such as user id, password,retype pass word, security question, answer and few more general fields like name,add etc.My query is when I click on submit button, eventhough if I have not selected my security question from the drop down listbox the user can type his answer and the page accepts the answer and gets submitted.Therefore I need the exact function that wont submit the form untill the question is selected and will give text msg beside the question field that "select your question" and not the alert box.I m using Javascript for this.Kindly advise me and thanks in advance.

-question by priyanka

Comment/Reply (w/o sign-up)

(G)lew
Replying to sportytalk I'm trying to use your code for a multiple drop down menu with a submit button exactly like this example. I'm using Dreamweaver and I'm not sure about the action='yourfile.Php' part of the code. I don't have a .Php file so I'm not sure what the action should=

Reply by Anon


Comment/Reply (w/o sign-up)

(G)Tim
javascript - 3 dropdown menus and submit
Multiple Drop Down Menus W/ Submit Button

Do you have an example of what the javascript code would look like for 3 drop down menus and a submit button?  Say menu one lists colors green and blue, menu two lists sizes large and small and menu three lists types cotton and polyester. The user would be taken to a particular web page based on their three selections.    


 


Comment/Reply (w/o sign-up)



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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

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       Username:          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 form action(check.php). I thought I cannot just use
    right? use bbcode " " tags when posting any computer code. Inserting it raw in the posting
    MAY break the forum formatting. Thanks. ....
  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
    (14)
    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.         2.             3.                 4.   ....
  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
    (5)
    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                                                  
                                                  I want to substitue the add button for an
    image CODE that i created but i want still to have the same funcitonlity when someone
    clicks. How can i do this? Thanks in advanced!....
  11. Button To Print Current Web Page
    (18)
    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 Male
    Female In the registering file I put the following (edited for the question): CODE $SQL =
    "INSERT into go_logintable(gender ) VALUES ('$gender')"; I have no idea if thats the
    right way to go, so please give me some pointers. ____________________________________ D....
  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
See Also,
advertisement


Multiple Drop Down Menus W/ Submit Button

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com