View Full Version : What does this Javascript do please?

07-09-2005, 09:50 PM
I have this script in the header of numerous pages of my site. The site was constructed a few years ago and now I can't remember what it does:

<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
// End -->

Anyone have an idea? Cheers :)

07-10-2005, 03:51 AM

This script looks like it is designed to select a web page from a drop down box and redirect the user to this page.

say you had this form on your page:


You would call the script using something like this:

<INPUT TYPE="button" VALUE="Go To URL" ONCLICK="formHandler(URLform);">

When the user clicks on the button they will be directed to the selected option, which will open in the current window (window.location.href = ...)


07-10-2005, 03:58 AM
Without seeing the markup that it is meant to go with, it is a little hard to tell. It probably was meant to do something like what this does:

<title>Drop Nav - Demo</title>
<script type="text/javascript">
function formHandler(form){
var URL = document.forms[form]['site'].options[document.forms[form]['site'].selectedIndex].value;
window.location.href = URL;
<form name="nav">
<select name="site">
<option value="http://www.yahoo.com">Yahoo
<option value="http://www.google.com">Google
<option value="http://www.codingforums.com">Coding Forums
<input type="button" value="Go" onclick="formHandler('nav')">