473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ 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="JavaS cript">
function selectInterests (frm)
{
// Obtain the first dimension position of the currently selected
var i = frm.adv_categor y.selectedIndex ;
var n = frm.adv_interes ts.selectedInde x;
if (i > 0){
// Inititalise the new adv_interests selection
frm.adv_interes ts.options.leng th = 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_interes ts.options[j-1].text =
arrTextInterest s[i][j];
frm.adv_interes ts.options[j-1].value =
arrValInterests[i][j];
}
frm.adv_interes ts.options[0].selected = true;
}
else{
// User has reselected the blank 'adv_interests' option
frm.adv_interes ts.options.leng th = 1;
frm.adv_interes ts.options[0].text ="--Please Select--
";
frm.adv_interes ts.options[0].value = "";
}
}
</script>

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

In the body:

<SELECT NAME="adv_categ ory"
ID="adv_categor y"onChange="sel ectInterests(fo rm1);">
<option value="0">--Please Select--</option>
<option value="3">Bankn otes</option>
<option value="5" selected>Books</option>
<option value="1">Coins </option>
<option value="4">Medal s</option>
<option value="6">Numis matic Circular</option>
</SELECT>

<SELECT multiple size="10" NAME="adv_inter ests" ID="adv_interes ts"
style="width:35 0px;">
<option value="">--Please Select--</option>
</SELECT>
<script language="JavaS cript">
var arrValInterests = new Array();
var arrTextInterest s = new Array();
arrValInterests[0] = new Array("0","0");
arrTextInterest s[0] = new Array("0","--All Categories--");
arrValInterests[1] = new
Array("3","0"," 752","...remove d...","724","65 3","654");
arrTextInterest s[1] = new Array("3","--All
Categories--","Abyssinia"," Afghanistan",". ..removed..."," USA","Venezuela ","Vietnam","We st
Indies","Yemen" ,"Yugoslavia"," Zanzibar");
arrValInterests[2] = new Array("5","0"," 661","...remove d...","662");
arrTextInterest s[2] = new Array("5","--All Categories--","British
Coins-All","...remove d...","Sylloge of Coins of the British Isles");
arrValInterests[3] = new Array("1","...r emoved...","36" );
arrTextInterest s[3] = new Array("1","--All
Categories--","...removed.. .","Treasure"," US Coins");
arrValInterests[4] = new Array("4","0"," 121","...remove d...","384");
arrTextInterest s[4] = new Array("4","--All Categories--","British
orders","...rem oved...","Singl e Campaign Medals");
arrValInterests[5] = new Array("6","0");
arrTextInterest s[5] = new Array("6","--All Categories--");
</script>
<script language="JavaS cript">
function selectInterests (frm)
{
// Obtain the first dimension position of the currently selected
var i = frm.adv_categor y.selectedIndex ;
var n = frm.adv_interes ts.selectedInde x;
if (i > 0){
// Inititalise the new adv_interests selection
frm.adv_interes ts.options.leng th = 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_interes ts.options[j-1].text = arrTextInterest s[i][j];
frm.adv_interes ts.options[j-1].value = arrValInterests[i][j];
}
frm.adv_interes ts.options[0].selected = true;
}
else
{
// User has reselected the blank 'adv_interests' option
frm.adv_interes ts.options.leng th = 1;
frm.adv_interes ts.options[0].text ="--Please Select-- ";
frm.adv_interes ts.options[0].value = "";
}
} </script>
Jul 23 '05 #1
3 1988
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_categ ory"
ID="adv_catego ry" onChange="selec tInterests(form 1);">


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="selec tInterests( 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
4967
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' ,'stmenu2','stsubmenu2','images/crt/images/cr_04.jpg' && setDefaults())">
3
3021
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 created as selected. May somebody give me an explanation ? <input type="button" value="test" onclick="test()"/> <select name="tagSelect"...
3
2079
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.6, the function msg works fine if it's installed as an onclick handler for the button, but fails as an onload handler for the page. The error is...
1
1597
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 src="http://info.onet.pl/_i/galeria/okulary/15.jpg" onload="var xx=document.getElementById('xxx'); xx.innerHTML+='<BR>LOADED'"
2
2409
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 page:
4
2449
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 value of an option in a select statement: <select id="usertypes" multiple="multiple"> <option value="0033">data1</option>
6
4682
by: Michael Landberg | last post by:
Hi is it possible to load multiple onload events in the body tag? Regards
3
2059
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 to fit the users monitor resolution. FitPic() creates certain variables that would be useful for other calculations, such as reporting the % of...
7
2056
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), loads. But in Firefox, they all load, when first loading the page. I am using this method to load all of the functions on first loading the page:...
0
7502
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
7434
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...
0
7946
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...
1
7457
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...
0
6026
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...
1
5360
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5078
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
744
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.