473,480 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple Functions in onLoad in Mozilla

Hi,

I have a script which isn't working in Mozilla based browser for some
reason. I'm trying to run two functions from the body onload tag and
it simply isn't happening.

I have a cascading menu, where the primary dropdown selection
determines the contents of a second dropdown. This is triggered by a
function in the onchange tag of the primarys select tag. When
triggered like this, the function and drop downs work fine. When
returning to the page I query a database to maintain state of the
primary dropdown and use the onload to trigger the function used in
the onchange to repopulate the second dropdown. As I say this works
fine in IE etc but not Mozilla based browsers.

Here's the code snippets. Anyone got any ideas?

In the header:
<script type="text/javascript">
function doOnload() {
selectInterests(form1)
preloadImages()
}
</script>
<script language="JavaScript">
function selectInterests(frm)
{
// Obtain the first dimension position of the currently selected
var i = frm.adv_category.selectedIndex;
var n = frm.adv_interests.selectedIndex;
if (i > 0){
// Inititalise the new adv_interests selection
frm.adv_interests.options.length = arrValInterests[i].length
- 1;
// Now select the the items associated with the selected
option
for (var j=1; j < arrValInterests[i].length; j++){
frm.adv_interests.options[j-1].text =
arrTextInterests[i][j];
frm.adv_interests.options[j-1].value =
arrValInterests[i][j];
}
frm.adv_interests.options[0].selected = true;
}
else{
// User has reselected the blank 'adv_interests' option
frm.adv_interests.options.length = 1;
frm.adv_interests.options[0].text ="--Please Select--
";
frm.adv_interests.options[0].value = "";
}
}
</script>

</head>
<body bgcolor="#FFFFFF" onLoad="doOnload();" leftmargin="0"
topmargin="0" marginwidth="0" marginheight="0">
<table border="0" width="100%" cellspacing="0" cellpadding="0">

In the body:

<SELECT NAME="adv_category"
ID="adv_category"onChange="selectInterests(form1); ">
<option value="0">--Please Select--</option>
<option value="3">Banknotes</option>
<option value="5" selected>Books</option>
<option value="1">Coins</option>
<option value="4">Medals</option>
<option value="6">Numismatic Circular</option>
</SELECT>

<SELECT multiple size="10" NAME="adv_interests" ID="adv_interests"
style="width:350px;">
<option value="">--Please Select--</option>
</SELECT>
<script language="JavaScript">
var arrValInterests = new Array();
var arrTextInterests = new Array();
arrValInterests[0] = new Array("0","0");
arrTextInterests[0] = new Array("0","--All Categories--");
arrValInterests[1] = new
Array("3","0","752","...removed...","724","653","6 54");
arrTextInterests[1] = new Array("3","--All
Categories--","Abyssinia","Afghanistan","...removed...","USA", "Venezuela","Vietnam","West
Indies","Yemen","Yugoslavia","Zanzibar");
arrValInterests[2] = new Array("5","0","661","...removed...","662");
arrTextInterests[2] = new Array("5","--All Categories--","British
Coins-All","...removed...","Sylloge of Coins of the British Isles");
arrValInterests[3] = new Array("1","...removed...","36");
arrTextInterests[3] = new Array("1","--All
Categories--","...removed...","Treasure","US Coins");
arrValInterests[4] = new Array("4","0","121","...removed...","384");
arrTextInterests[4] = new Array("4","--All Categories--","British
orders","...removed...","Single Campaign Medals");
arrValInterests[5] = new Array("6","0");
arrTextInterests[5] = new Array("6","--All Categories--");
</script>
<script language="JavaScript">
function selectInterests(frm)
{
// Obtain the first dimension position of the currently selected
var i = frm.adv_category.selectedIndex;
var n = frm.adv_interests.selectedIndex;
if (i > 0){
// Inititalise the new adv_interests selection
frm.adv_interests.options.length = arrValInterests[i].length - 1;
// Now select the the items associated with the selected option
for (var j=1; j < arrValInterests[i].length; j++){
frm.adv_interests.options[j-1].text = arrTextInterests[i][j];
frm.adv_interests.options[j-1].value = arrValInterests[i][j];
}
frm.adv_interests.options[0].selected = true;
}
else
{
// User has reselected the blank 'adv_interests' option
frm.adv_interests.options.length = 1;
frm.adv_interests.options[0].text ="--Please Select-- ";
frm.adv_interests.options[0].value = "";
}
} </script>
Jul 23 '05 #1
3 1977
Disco-181 wrote:
Hi,

I have a script which isn't working in Mozilla based browser for some
reason. I'm trying to run two functions from the body onload tag and
it simply isn't happening.
In the header:
<script type="text/javascript">
function doOnload() {
selectInterests(form1)
preloadImages()
}
</script>


form1 looks like an incomplete reference to me.

Mick
Jul 23 '05 #2
Disco-181 wrote:
<snip>
... . As I say this works
fine in IE etc but not Mozilla based browsers.

Here's the code snippets. Anyone got any ideas?

In the header:
<script type="text/javascript">
function doOnload() {
selectInterests(form1)
preloadImages()
} <snip>

IE makes named forms into named properties of the global/window object
so that their names can be used as identifiers in code to refer to the
corresponding element. As a result the identifier - form1 - would refer
to a form with the name, or ID, "form1". Mozilla browsers do no such
thing and the identifier - form1 - will resolve as an undefined property
of the global object. So Mozilla will error in the opening lines of
the - selectInterests - function. (as the javascript console would have
revealed).

Cross-browser code would use the - document.forms - collection to
acquire a reference to the form element so it could be passed to the
function call:-

function doOnload() {
var frm;
if(
(document.forms) &&
(frm = document.forms['form1'])
){
selectInterests(frm);
}
preloadImages();
}
<SELECT NAME="adv_category"
ID="adv_category" onChange="selectInterests(form1);">


Both Mozilla and IE provide a custom scope chain for the internally
generated function created from event handling attribute string values.
These custom scope chains are non-standard and not universally
implemented in browsers, and IE and Mozilla generate different chains,
but both will place the document on the scope chain of an event handling
function generated for a controls. As a result the unqualified
identifier - form1 - will be resolved as a property of the document that
refers to the containing form. However, the W3C HTML DOM specification
(and all older scriptable browsers) offers a - form - property of form
controls that refers to their containing form. As a result a standard
(and more widely supported/reliable) method of passing a reference to
the containing form from an event handling function on a contained form
control is to use - this.form -:-

onChange="selectInterests( this.form );"

Richard.
Jul 23 '05 #3
Thanks Richard. Thats working fine now.
Jul 23 '05 #4

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

Similar topics

3
4965
by: steve | last post by:
Hi all I have this onLoad event it is working fine but I'm just queries is this the right ware to do it? <body onLoad="st_setkopcheta1(10,10,10,'stmenubottom','stmenu1','stsubmenu1'...
3
3013
by: Max Weber | last post by:
Try to run the code below in a page. You will notice than when you switch the multiple attribute of the SELECT tag, only one option is displayed as selected although multiple options have ben...
3
2071
by: kj | last post by:
This problem is driving me nuts. The code at the end of this post below works fine with IE, but fails with Mozilla. You can see it in action at http://tinyurl.com/2jvo3 With Mozilla 1.4 and...
1
1583
by: Krzysiek S. | last post by:
Hi, I need your help. How to get multiple onLoad in Opera (v.7)? Example shows what I mean - it works well IE and Mozilla, but not in Opera :( (click an image): <IMG...
2
2400
by: John J. Lee | last post by:
I was cheered to see that this guy claims to have solved the problem with onload only firing very late: http://dean.edwards.name/weblog/2005/09/busted/ However, "ash" comments on that...
4
2438
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the...
6
4679
by: Michael Landberg | last post by:
Hi is it possible to load multiple onload events in the body tag? Regards
3
2050
by: zepdad | last post by:
I'm new to forum and am learning javascript. I appreciate your help and patience in advance. I run an image gallery website that uses an onload event called FitPic() to scale image and window sizes...
7
2041
by: burtonfigg | last post by:
On this page: http://jimpix.co.uk/default-ajax1.asp When viewed in IE6, only the wallppaper ajax section (which is 1 of 4 ajax sections, along with ecards / news / photo ecards and wallpapers),...
0
6918
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...
0
7057
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,...
1
6756
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...
0
7003
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...
0
5357
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,...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1310
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 ...
0
199
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...

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.