Sign in to follow this  
namingway

[web] help using forms

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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" />

Share this post


Link to post
Share on other sites
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 javascript at all (which is better for some browsers).

Share this post


Link to post
Share on other sites
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'?

Share this post


Link to post
Share on other sites
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" />

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this