Javascript code only works in Netscape, yet no Scirpt error???

J

John

Code is as follows:

document.write('<FORM name="horseform">');
document.write(' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size:
8pt">');
document.write(' <OPTION VALUE="http://my.domain.com/cat1.html">Category
1</OPTION>');
document.write(' <OPTION VALUE="http://my.domain.com/cat2.html">Category
2</OPTION>');
document.write(' <OPTION VALUE="http://my.domain.com/cat3.html">Category
3</OPTION>');
document.write(' </SELECT>');
document.write(' <a href="javascript:;" title="Click here"
onclick="goto_PetCategoryURL(document.horseform.elements.horsebrandslist)"><img
border="0" src="../images/horse/someimage.gif" width="29" height="20"
alt="Click here" align="absbottom"></a>');
document.write('</FORM>');


In a separate .js file, the function "goto_PetCategoryURL" looks like this:

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
 
L

Lee

John said:
Code is as follows:

document.write('<FORM name="horseform">');
document.write(' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size:
8pt">');
document.write(' <OPTION VALUE="http://my.domain.com/cat1.html">Category
1</OPTION>');
document.write(' <OPTION VALUE="http://my.domain.com/cat2.html">Category
2</OPTION>');
document.write(' <OPTION VALUE="http://my.domain.com/cat3.html">Category
3</OPTION>');
document.write(' </SELECT>');
document.write(' <a href="javascript:;" title="Click here"
onclick="goto_PetCategoryURL(document.horseform.elements.horsebrandslist)"><img
border="0" src="../images/horse/someimage.gif" width="29" height="20"
alt="Click here" align="absbottom"></a>');
document.write('</FORM>');


In a separate .js file, the function "goto_PetCategoryURL" looks like this:

function goto_PetCategoryURL(object) {
if (object.selectedIndex > 0) {
window.location.href = object.options[object.selectedIndex].value;
}
return;
}

1. You've got no way of going to cat1.html, since selectedIndex
for that choice is 0.

2. Your onclick handler should return false:
onclick="goto_PetCategoryURL(...);return false"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top