Why dont my links work?

Perseus

Registered
Here is my code:

<form action="get">
<select size="1" name="ListBoxURL">
<option value="http://my.musicresults.com/musiceducation.html">Anna Maria College</option>
<option value="http://www.bridgew.edu/Music/MCMENC.cfm">Bridgewater State College</option>
</select> <input type="button" value="Go" onclick="gotoLink(this.form)" name="button" />
<script language="JavaScript" type="text/css">
<!--
function gotoLink(form) {
var OptionIndex=form.ListBoxURL.selectedIndex;
parent.location = form.ListBoxURL.options[OptionIndex].value;}
//-->
</script>
</form>


Issue: When I test this code (its inside an <li> tag) in browsers, the links dont work. (The GO button in otherwords). For some reason it only works in Safari. What can I do?
 
OK, first, why is your script of type "text/css"?

And why is it underneath your code? Good script functions belong in the header.

I doubt it's that simple, but it still ought to be fixed.
 
Ooops, my bad. Logged into wrong account. Anyway...
Code:
<script language="JavaScript" type="text/css">
Can just be:
Code:
<script type="text/javascript">

I ran the script through Firefox's JavaScript console; it spits out an error, It does not make any sense to me. Can you tell us exactly what the script should be doing?
 
First, this javascript should go inside the, <head> here somewhere </head>, tags or you code.

<script LANGUAGE="JavaScript">
<!--
function gotoLink(form) {
var OptionIndex=form.ListBoxURL.selectedIndex;
parent.location = form.ListBoxURL.options[OptionIndex].value;}
//-->
</script>

The rest of the code should go in the body. I've reformated it for you slightly, leaving some 'white space'. It's a lot less easy to make mistakes and get confused, if you seperate the code out into sections. It helps me anyway. Good luck :)

<form action="get">

<select size="1" name="ListBoxURL">
<option value="http://my.musicresults.com/musiceducation.html">Anna Maria College</option>
<option value="http://www.bridgew.edu/Music/MCMENC.cfm">Bridgewater State College</option>
</select>

<input type="button" value="Go" onclick="gotoLink(this.form)" name="button" />

</form>

EDIT: do what tex said too.
 
You should also put an identifying tag into the <form> tag, since you're referring to it as "form".

I'd have <form name="navigationForm"...>

And why not just assign to the button simple JS that says "onClick="parent.location=navigationForm.ListBoxURL.options[navigationForm.ListBoxURL.selectedIndex].value""?

Beware too, that in this current age, many users switch off JavaScript in their browsers. You will probably want non-JS navigation if you can help it (at least supplementing this)
 
Back
Top