Click to See Complete Forum and Search --> : Simple Question for the Experts


jerseyralph
12-02-2003, 05:32 AM
I have limited exposure to javascript so I need some basic help.

I am using the follow script for a drop down menu box:

<head>
<script language=JavaScript>
<!--
function Navigate() {
var number = NavSelect.selectedIndex;
location.href = NavSelect.options[number].value; }
// -->
</script>
</head>

Then within the body of the page:

<select name="NavSelect" onChange="Navigate(this.form)">
<option value="" SELECTED>Click to Navigate
<option value="http://governmenteducators.us/munoff/">Municipal Clerks
<option value="http://governmenteducators.us/munoff/">Finance Officers
<option value="http://governmenteducators.us/munoff/">Tax Collectors
<option value="http://governmenteducators.us/munoff/">Public Works Managers
<option value="http://governmenteducators.us/constcode/">Construction Code Officials
<option value="http://governmenteducators.us/constcode/">Technical Assistants
<option value="http://governmenteducators.us/constcode/">Multiple Dwelling Inspectors
</select>

The drop down box works fine in the latest MS IE broswer, but will not work in either Netscape or Mozilla.

What am I missing? Thanks

Ralph

lillu
12-02-2003, 06:11 AM
Oh, I reckon it's because you reference this.form without actually embedding it into a form.

What about this?

<select name="NavSelect" onChange="return ="Navigate(this);" size="1">

The other thing is. When you pass a reference from a form, you should also be getting it in the function as an argument.

function Navigate(f) //f is the NavSelect form's current object
{

var number = f.selectedIndex;
location.href = f.options[number].value;

return true;
}
</script>

Changing location.href works fine in Explorer on Mac, Explorer 5.5+ on Windows and Netscape 6.

If it still doesn't work for some reason in another browser,
try this:

<script type="text/javascript" language="javascript">

function Navigate(f){
var number = f.selectedIndex;
var url = f.options[number].value;
window.open(url,'_top'); //make sure you dont put spaces inside (url,'_top'), NN does not like it
return true;
}

</script>


Oh, I forgot to add, that you should check if javascript is enabled in browsers such as NN or Mozilla. If not, this navigation will not work at all.

ray326
12-02-2003, 11:25 AM
NavSelect.selectedIndex

This is not a valid DOM reference. The reference should be

document.formname.NavSelect.selectedIndex

Since you don't include the form tags I don't know what your form name is.