[web] help using forms

Started by
6 comments, last by Sander 16 years, 10 months ago
I am setting up a website where at the top a list menu containing some different categories are, next to it is a button that says 'Go'. I'd like to know how you set it up so that what ever is selected in the list menu go will send you to that page e.g. If C was selected it will take you to a page with C tutorials.
Advertisement
The simplest method is:
<select id="menu">  <option value="/page1.html">Page 1</option>  <option value="/page2.html">Page 2</option></select><input type="button" value="Go" onclick="if (document.getElementById('menu').value) location.href=document.getElementById('menu').value" />


If you also want it to go automatically, change the select to look like:
<select id="menu" onchange="if (this.value) location.href=this.value" />
You can also do a regular HTTP POST to the server and then do a 301 redirect to the correct URL. That way you do not need to mess with &#106avascript at all (which is better for some browsers).

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Quote:Original post by konForce

If you also want it to go automatically, change the select to look like:
<select id="menu" onchange="if (this.value) location.href=this.value" />


With this method, how do I get the page to open up in 'mainFrame'?
You're using frames? Ugh... don't...

But to answer your question, it would be something like:

<select id="menu" onchange="if (this.value) windows.parent.mainFrame.location.href=this.value" />

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Hey what's wrong with frames? I know plenty of sites that use them.

Also its not loading anymore at all.

[Edited by - namingway on June 2, 2007 6:52:42 AM]
What's wrong with frames?!

Read the first two and learn to hate 'em
Quote:Original post by namingway
Also its not loading anymore at all.


I said it's something like that. I didn't test it. I guess it's window.parent, not windows.parent.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement