Log in

View Full Version : body onLoad creates conflicts on pages not utilizing the script



Robin_TWD
02-12-2008, 04:04 PM
1) Script Title: Chained Selects

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm

3) Describe problem: The script calls for editing the <body> tag to look like:
<body onLoad="initListGroup('series', document.forms[0].seriesName, document.forms[0].height, 'cs')">

My problem is that the site is created using templates in Dreamweaver, which means that the only way I can find of editing the body tag for the one page I need this script on, is to edit it in the master template. Doing so changes the <body> tag for every page on the site, which is fine, except that now each page shows an error marker with the following error.

Error: 'document.forms.0seriesName' is null or not an object

Is there a way to either fix this error message, or to add the onLoad to the body tag of just the one page I need it on, without changing every page in the site, while still utilizing a template?

Any help you can give me, would be greatly appreciated.

jscheuer1
02-12-2008, 05:46 PM
That's stupid. I don't know DW, but there must be an easy way to have one page be a little different. In any case though, until you figure that out, try this:


<body
onload="if(document.forms[0]&&document.forms[0].seriesName){
initListGroup('series', document.forms[0].seriesName, document.forms[0].height, 'cs')
}">

Robin_TWD
02-12-2008, 05:53 PM
John,

Thank you so much for your post, your solution worked perfectly!

Master_script_maker
02-12-2008, 05:54 PM
put this in the head:

<script type="text/javascript">
function run() {
initListGroup('series', document.forms[0].seriesName, document.forms[0].height, 'cs');
}
document.getElementsByTagName("body")[0].onLoad=run;
</script>