kvarnerexpress
Feb 15 2006, 11:06 PM
| | 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
Feb 15 2006, 11:31 PM
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! 
Reply
Tyssen
Feb 16 2006, 12:05 AM
Sportytalk's example could be improved further by using a switch/case statement instead of all the if elses.
Reply
methane
Feb 20 2006, 03:28 AM
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!  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
Feb 20 2006, 09:46 AM
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..
Reply
nelarozi
Feb 20 2006, 10:04 AM
use a program like 1 Cool Menu FX Tool! this program is payable but perfect for biginners
Reply
Trap FeedBacker
Mar 18 2008, 12:54 PM
Replying to methaneI'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
Recent Queries:--
multiple dropdown link to page - 7.14 hr back.
-
php multiple submit buttons - 9.12 hr back.
-
mysql multiple drop down menus using php - 9.60 hr back.
-
drop down submit button - 12.59 hr back.
-
input button size large in table - 15.76 hr back.
-
how to get the values from multiple drop down boxes - 17.21 hr back.
-
multiple submit buttons on one php page - 18.78 hr back.
Similar Topics
Keywords : multiple, drop, menus, w, submit, button
- Question About Multiple Voting Post Or Get Methods
Multiple voting post or get methods on 1 page (3)
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....
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....
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! ....
Refresh Page After Back Button Hit
(5) 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. ....
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? ....
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.....
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?....
Radio Button
(3) 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.....
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....
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.....
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....
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....
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....
Looking for multiple, drop, menus, w, submit, button
|
|
Searching Video's for multiple, drop, menus, w, submit, button
|
advertisement
|
|