WDN Logo

home-icon Home / HTML / HTML selection list without a submit button

HTML selection list without a submit button

HTML selection list without a submit button

We all strive for good navigation on our web sites. It’s the aim of any web developer to have a page linked to another by a maximum of 2 clicks. Drop down lists (HTML <form> <select> elements) can be placed on all pages with links to the important pages on the web site. JavaScript allows us to make the visitor jump to a particular page by selecting an item from the drop down menu – and that too without a submit button. So you do not need to know any server-side language. JavaScript makes it easy to create a navigation list without a submit button. We employ the onChange() event handler along with location property of the window object.

// The following function is placed in the HTML head
function nav()
   {
   var w = document.myform.mylist.selectedIndex;
   var url_add = document.myform.mylist.options[w].value;
   window.location.href = url_add;
   }


// This code is placed in the HTML body
<form name="myform">
Jump to:
<select name="mylist" onChange="nav()">
<option value="http://www.youtube.com">YouTube</option>
<option value="http://www.9gag.com">9GAG</option>
<option value="http://www.wikipedia.org">Wikipedia</option>
<option value="http://www.yahoo.com">Yahoo!</option>
<option value="http://www.deviantart.com">DeviantArt</option>
<option value="http://www.flickr.com">Flickr</option>
<option value="http://www.twitter.com">Twitter</option>
<option value="http://www.tumblr.com">Tumblr</option>
</select>
</form>

Click here to see how this works!

The values of all the options in this selection list are URLs. The onChange() event handler calls nav() function. This function stores the value of the selected item (the URL) in url_add variable. The window.location.href is then set to this variable.
Note: This selection list does not employ a “submit” button.

Sponsored Links

Search

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

joke-i-heard-you-want-to-be-a-web-developer

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

The memorable Sun Microsystems logo was designed by Stanford professor, Vaughan Pratt. The logo has the word "SUN" at different angles. [more...]

Share on Whats app Share on Facebook Share on Twitter Share on Google plus