View Full Version : multiple javascripts - help needed

09-04-2008, 06:33 PM
Granted my knowledge of javascripts is not brillian so some help on this query would be great:

I have the following 2 entries in the <head> of my page. it turns up an error and i need to use both. could someone explain best way of doing this:

<script type="text/javascript" src="dropdowntabfiles/dropdowntabs.js">


<script type="text/javascript">

if (document.getElementById)
document.documentElement.className = 'jsclass'; //hide content for DOM capable browsers

var randomcontentdisplay={
divholders:new Object(),
masterclass: "randomcontent",

if (!document.getElementById)
var alldivs=document.getElementsByTagName("div")
var randomcontentsearch=new RegExp(this.masterclass+"\\s+(group\\d+)", "i") //check for CSS class="randomcontent groupX" (x=integer)
for (var i=0; i<alldivs.length; i++){
if (randomcontentsearch.test(alldivs[i].className)){
if (typeof this.divholders[RegExp.$1]=="undefined") //if array to hold this group of divs doesn't exist yet
this.divholders[RegExp.$1]=new Array() //create array first
this.divholders[RegExp.$1].push(alldivs[i]) //add this div to the array

for (group in this.divholders){ //loop thru each array within object
var chosenOne=Math.floor(Math.random()*this.divholders[group].length) //randomly pick one entry from array
this.divholders[group][chosenOne].style.display="block" //display content corresponding to the chosen entry


Philip M
09-04-2008, 06:57 PM
The solution is usually to be found at:-


If that does not deal with it, then you must check that there is no duplication of function or variable names between the two scripts.

We are sorry that as a result of a typographical error we referred to General X as "a bottle-scarred old veteran". This should of course have read "a battle-scared old veteran".

09-04-2008, 07:34 PM
thanks for this philip. i already had a read through that page on javascriptkit and it speaks of conflicts between
1) <body ONLOAD="runscript()">
2) window.onload=runscript //appears inside the <script> tag

neither of my scripts seem to run from the body tag or using the window.onload. i cant seem to find variable that clashes either . . .

Philip M
09-04-2008, 07:41 PM
What error messages do you get?