473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Code is as follows:

document.write( '<FORM name="horseform ">');
document.write( ' <SELECT SIZE="1" NAME="horsebran dslist" STYLE="font-size:
8pt">');
document.write( ' <OPTION VALUE="http://my.domain.com/cat1.html">Cate gory
1</OPTION>');
document.write( ' <OPTION VALUE="http://my.domain.com/cat2.html">Cate gory
2</OPTION>');
document.write( ' <OPTION VALUE="http://my.domain.com/cat3.html">Cate gory
3</OPTION>');
document.write( ' </SELECT>');
document.write( ' <a href="javascrip t:;" title="Click here"
onclick="goto_P etCategoryURL(d ocument.horsefo rm.elements.hor sebrandslist)"> <img
border="0" src="../images/horse/someimage.gif" width="29" height="20"
alt="Click here" align="absbotto m"></a>');
document.write( '</FORM>');
In a separate .js file, the function "goto_PetCatego ryURL" looks like this:

function goto_PetCategor yURL(object) {
if (object.selecte dIndex > 0) {
window.location .href = object.options[object.selected Index].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
Jul 23 '05 #1
2 1314
Lee
John said:

Code is as follows:

document.write ('<FORM name="horseform ">');
document.write (' <SELECT SIZE="1" NAME="horsebran dslist" STYLE="font-size:
8pt">');
document.write (' <OPTION VALUE="http://my.domain.com/cat1.html">Cate gory
1</OPTION>');
document.write (' <OPTION VALUE="http://my.domain.com/cat2.html">Cate gory
2</OPTION>');
document.write (' <OPTION VALUE="http://my.domain.com/cat3.html">Cate gory
3</OPTION>');
document.write (' </SELECT>');
document.write (' <a href="javascrip t:;" title="Click here"
onclick="goto_ PetCategoryURL( document.horsef orm.elements.ho rsebrandslist)" ><img
border="0" src="../images/horse/someimage.gif" width="29" height="20"
alt="Click here" align="absbotto m"></a>');
document.write ('</FORM>');
In a separate .js file, the function "goto_PetCatego ryURL" looks like this:

function goto_PetCategor yURL(object) {
if (object.selecte dIndex > 0) {
window.location .href = object.options[object.selected Index].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_P etCategoryURL(. ..);return false"

Jul 23 '05 #2
John wrote:
Code is as follows:
<snip>

function goto_PetCategor yURL(object) {
if (object.selecte dIndex > 0) {
window.location .href = object.options[object.selected Index].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


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_PetCategor yURL(object) {
if (object.selecte dIndex > -1){
alert(object.op tions[object.selected Index].value);
window.location .href = object.options[object.selected Index].value;
}
return;
}
</script>

</head>

<body>
<script type="text/javascript">
var s='<FORM name="horseform ">';
s+=' <SELECT SIZE="1" NAME="horsebran dslist" STYLE="font-size:8pt">';
s+=' <OPTION VALUE="http://my.domain.com/cat1.html"
SELECTED>Catego ry 1</OPTION>';
s+=' <OPTION VALUE="http://my.domain.com/cat2.html">Cate gory
2</OPTION>';
s+=' <OPTION VALUE="http://my.domain.com/cat3.html">Cate gory
3</OPTION>';
s+=' </SELECT>';
s+=' <a href="#;" title="Click Here"
onclick="goto_P etCategoryURL(d ocument.horsefo rm.elements.hor sebrandslist)"> ';
s+='<img border="0" src="someimage. gif" width="29" height="20"
alt="Click here" align="absbotto m"></a>';
s+='</FORM>';
document.write( s);
</script>
</body>
</html>
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.