473,768 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does event for SELECT not fire in Mozilla?

Why does this not work in Mozilla ?

<http://homepage.ntlwor ld.com/mark.pawelek/code/animals.html>

The optHabitat_chan ge() event does not fire. What am I doing wrong
here?

PS: It should repopulate the 2nd combo based upon the value of the
selected item in the first, just like it does in IE.

Jul 23 '05 #1
2 3486
[Follow-ups set to comp.lang.javas cript]

On Fri, 24 Sep 2004 10:02:55 +0100, mark4asp
<ma************ ****@ntlworld.c om> wrote:
Why does this not work in Mozilla ?

<http://homepage.ntlwor ld.com/mark.pawelek/code/animals.html>

The optHabitat_chan ge() event does not fire. What am I doing wrong
here?


It does fire. If you look at the error console, you'll see Mozilla
complain.

You see unfortunately, IE hasn't followed the W3C with regards to the
HTMLSelectEleme nt.add method. IE uses a number for the second argument,
and an optional one at that. However, the W3C DOM states that the second
argument is a required object reference.

The two simply aren't compatible (though good 'ol Opera allows both).

There seems to be four options available.

1) Fall back on the old approach of using the Option constructor to create
new OPTION elements and append them using the options collection. This
will be supported by older scriptable browsers.
2) Use try/catch to determine whether an error occurs whilst trying to use
the object or number version of the method. Use the other approach in the
catch clause. This won't be supported by older browsers because a) they
don't support try/catch, and b) they won't support DOM 1.
3) Use appendChild to add the OPTION elements. I haven't thoroughly tested
this, but it appears to work. This won't be supported by older browsers as
they don't support DOM 1.
4) Use the (preferred) server-side approach. This will be supported by old
and new browsers alike, scriptable or otherwise.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
On Fri, 24 Sep 2004 09:35:01 GMT, "Michael Winter"
<M.******@bluey onder.co.invali d> wrote:
[Follow-ups set to comp.lang.javas cript]

On Fri, 24 Sep 2004 10:02:55 +0100, mark4asp
<ma*********** *****@ntlworld. com> wrote:
Why does this not work in Mozilla ?

<http://homepage.ntlwor ld.com/mark.pawelek/code/animals.html>

The optHabitat_chan ge() event does not fire. What am I doing wrong
here?


It does fire. If you look at the error console, you'll see Mozilla
complain.

You see unfortunately, IE hasn't followed the W3C with regards to the
HTMLSelectElem ent.add method. IE uses a number for the second argument,
and an optional one at that. However, the W3C DOM states that the second
argument is a required object reference.

The two simply aren't compatible (though good 'ol Opera allows both).

There seems to be four options available.

1) Fall back on the old approach of using the Option constructor to create
new OPTION elements and append them using the options collection. This
will be supported by older scriptable browsers.
2) Use try/catch to determine whether an error occurs whilst trying to use
the object or number version of the method. Use the other approach in the
catch clause. This won't be supported by older browsers because a) they
don't support try/catch, and b) they won't support DOM 1.
3) Use appendChild to add the OPTION elements. I haven't thoroughly tested
this, but it appears to work. This won't be supported by older browsers as
they don't support DOM 1.
4) Use the (preferred) server-side approach. This will be supported by old
and new browsers alike, scriptable or otherwise.

Hope that helps,
Mike


It helped but the code still didn't work in Mozilla - for a different
reason which I was never able to figure out!

I fixed it by passing in the value of the item to be selected instead
of the index to be selected into the two functions loadOpt() and
optHabitat_chan ge(). This is much more logical even if it needs a line
or two of code more. I dispense with the stupid index positions and
use the values (which are the numbers in my data arrays anyway).

I include the fixed code because I always like a complete solution for
the benefit of any stranger who may have a similar problem in future.
[Oh yeh, and I've decided that Google is a nice place to store bits of
code that one may need in future too!]

I also had to change the way options were deleted as well as created.

<html>
<head>
<title>Funny Animals</title>
<script language="javas cript" type="text/javascript">
<!--
// Start of database
habitats = {
1:"arctic",
2:"desert",
3:"ocean" }

// "name", "habitat", "type", "page #"
creatures = {
1:["camel", "2", "10", "1¸14"],
2:["polar bear", "1", "10", "1¸14"],
3:["scorpion", "2", "10", "1¸14"],
4:["tuna", "3", "10", "1¸14"],
5:["whale", "3", "", "9"] }

// Initialise HTML
window.onload = Initialise;

// Core code
function getObj(oTxt) {
return document.getEle mentById(oTxt);
}

function toUpper(w) {
return (w.charAt(0).to UpperCase() + w.substring(1))
}

function Int(n){
return parseInt(n);
}
// Core code END

// Initialise & Events
function Initialise(){
loadOpt(getObj( 'optHabitat'), habitats, 1);
optHabitat_chan ge(getObj('optC reature'), 1);
}

// selVal = value of row to be selected.
function loadOpt(oCbo, ary, selVal) {
var key;
var i = 0;
for (key in ary) {
oCbo.options[oCbo.options.le ngth] = new Option(toUpper( ary[key]),
key);
oCbo[i].selected = (oCbo.options.v alue==selVal) ? true : false;
i++;
}
}

function makeOption(obj, text) {
if (obj!=null && obj.options!=nu ll)
obj.options[obj.options.len gth] = new Option(text, value)
}

function removeAllOption s(oCbo) {
for (var i=(oCbo.options .length-1); i>=0; i--)
oCbo.options[i] = null;
oCbo.selectedIn dex = -1
}

function optHabitat_chan ge(oCbo, habitat) {
var s = '';
var key;
removeAllOption s(oCbo);
for (key in creatures) {
s = creatures[key][1].toString();
arow = s.split('¸');
if (habitat==Int(a row[0]))
oCbo.options[oCbo.options.le ngth] = new
Option(toUpper( creatures[key][0]), key);
}
return true
}

// Initialise & Events END

//-->
</script>
</head>

<body>
<p>Creatures:<b r />
<select id="optHabitat "
onchange="optHa bitat_change(ge tObj('optCreatu re'),this.value )"></select><br>
<!-- ,this.options(t his.selectedInd ex).value -->
<select id="optCreature "></select></p>
</body>
</html>
Jul 23 '05 #3

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

Similar topics

4
3607
by: Brian Glen Palicia | last post by:
My goal is to accept input from the user into a text box and then parse the data using split(). The first step is this tiny program to test the split() function. It runs in IE, but in Mozilla it just hangs and keeps loading forever. I checked around on the web and in USENET, but I haven't seen any mention of split() not working in Mozilla. Thoughts? Thanks in advance. <HTML> <HEAD> </HEAD>
9
1773
by: chandramohan.mani | last post by:
Does Event handlers work in netscape. If yes means can anyone please help me. <HTML><SCRIPT LANGUAGE="JScript"> function mouseclick() { alert("I was clicked on " + window.event.srcElement.tagName); } </SCRIPT> <BODY onclick="mouseclick()"> <H1>Welcome!</H1>
1
2595
by: Duwayne | last post by:
I am having a lot of trouble with an ascx page that has a textbox that *should fire a textchange event when the text changes. The main aspx page dynamically loads the ascx page and has a image button that initiates the submit. during submit, 2 events *should fire, 1 from the textbox and 1 from the image button. The image button event always fire but the textbox textchange event does not. Anyone has any ideas? Notes: During postback, I...
0
1079
by: Charles Law | last post by:
Is there a way to get the MouseEnter event to fire for a user control that inherits from UpDownBase? The event is hidden, and does not fire when the mouse enters the control. TIA Charles
8
5131
by: ApexData | last post by:
I'm using the OnKeyDown event in hopes of capturing a key being held down during the initial startup of my application. Does anyone know, at what point the OnKeyDown event fires? I checked to see if the key would be captured in the OnOpen and OnLoad or Initial OnCurrent event, but this does not seem to be the case. Can I capture a key in these events? Public CkOnOpenKey As Boolean CkOnOpenKey = True 'Placed in the OnOpen event
1
1492
by: John Dalberg | last post by:
What causes a server event to fire when something happens on the client? Say a user changed the gridview's page index, the server side PageIndexChanged event is fires. What makes PageIndexChanged fires? Is it a field in the viewstate? Is it a value in the forms collections? I am trying to understand the mechanism of communication between the browser and the server. John Dalberg
0
1610
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that suggested they had an img tag with src="", I decided to look for instances of "src" and one by one start removing that code to see if it changed anything. Below is the one that, when I removed it, although it broke the flash menus and header, solved...
6
1332
by: danielalrease | last post by:
The flash does not appear in mozilla fire fox even i have been downloaded the adobe, but i able to view it in IE. anyone can help on this issue ? website : www.ring8.com.my
6
2542
by: Harry | last post by:
Hi All VS 2008 Pro It appears that the form_closing event of a form may not always fire. I put an explicit lock on a customer record when it is open for edit and then remove the lock in the form_closing event when the form is closed. This used to work fine in VB6 but appears to be a bit unreliable in VB.Net. code------------------------------------------------------------------
0
9413
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10188
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9848
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5292
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5429
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3941
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
3
2810
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.