...

View Full Version : What does this Javascript do please?



Azam.net
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:



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


Anyone have an idea? Cheers :)

sparks80
07-10-2005, 03:51 AM
Hi,

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:

<FORM NAME="URLform">
<SELECT>
<OPTION>http://www.somewhere.com/url1.html"</OPTION>
<OPTION>http://www.somewhere.com/url2.html"</OPTION>
<OPTION>http://www.somewhere.com/url3.html"</OPTION>
</SELECT>
</FORM>

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 = ...)

Mark

jscheuer1
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:

<html>
<head>
<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;
}
</script>
</head>
<body>
<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
</select>
<input type="button" value="Go" onclick="formHandler('nav')">
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum