Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    multiple javascripts - help needed

    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>


    and

    <script type="text/javascript">



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


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

    init:function(){
    if (!document.getElementById)
    return
    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
    }
    }
    this.showone()
    },

    showone:function(){
    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
    }
    }
    }

    </script>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    The solution is usually to be found at:-

    http://www.javascriptkit.com/javatut...iplejava.shtml


    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".

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 . . .

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    What error messages do you get?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •