| re: Javascript code only works in Netscape, yet no Scirpt error???
John wrote:
[color=blue]
> Code is as follows:
> <snip>
>
> function goto_PetCategoryURL(object) {
> if (object.selectedIndex > 0) {
> window.location.href = object.options[object.selectedIndex].value;
> }
> return;
> }
>
> In Netscape (I use version 7), all works OK. In IE or Opera, when I click
> the image, nothing happens. No error shows in the Opera JavaScript Console
> or the bottom left of IE. Who can solve this mystery?
> Thanks,
> Don[/color]
The first selectedindex is 0, you ignore it with your if condition.
Also, I believe it's more efficient to concatenate a string several
times and to one document.write than to do multiple document.write.
This works in my IE 6, Firefox 1.0.1, Netscape 7.2:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>select</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function goto_PetCategoryURL(object) {
if (object.selectedIndex > -1){
alert(object.options[object.selectedIndex].value);
window.location.href = object.options[object.selectedIndex].value;
}
return;
}
</script>
</head>
<body>
<script type="text/javascript">
var s='<FORM name="horseform">';
s+=' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size:8pt">';
s+=' <OPTION VALUE="http://my.domain.com/cat1.html"
SELECTED>Category 1</OPTION>';
s+=' <OPTION VALUE="http://my.domain.com/cat2.html">Category
2</OPTION>';
s+=' <OPTION VALUE="http://my.domain.com/cat3.html">Category
3</OPTION>';
s+=' </SELECT>';
s+=' <a href="#;" title="Click Here"
onclick="goto_PetCategoryURL(document.horseform.el ements.horsebrandslist)">';
s+='<img border="0" src="someimage.gif" width="29" height="20"
alt="Click here" align="absbottom"></a>';
s+='</FORM>';
document.write(s);
</script>
</body>
</html> |