2 x function...need some help

Discussion in 'JavaScript' started by piri00, Apr 17, 2010.

  1. #1
    Hi

    I would like to run two different function but what I need is that First function will run when page load and when first function is done then second function will start and when second function is done then again first function will start and actually again it will repeat same (1 function, 2 function and again 1 function and 2 function)

    This is the script which highlights letters with one colour and I am trying to do that it will highlights one colour and after that second colour and start from beginning.

    Thanks for any help
    var message="Welcome to JavaScript Kit!"
    var neonbasecolor="gray"
    var neontextcolor="yellow"
    var flashspeed=100  //in milliseconds
    
    ///No need to edit below this line/////
    
    var n=0
    if (document.all||document.getElementById){
    document.write('')
    for (m=0;m<message.length;m++)
    document.write('<span id="neonlight'+m+'">'+message.charAt(m)+'</span>')
    document.write('')
    }
    else
    document.write(message)
    
    function crossref(number){
    var crossobj=document.all? eval("document.all.neonlight"+number) : document.getElementById("neonlight"+number)
    return crossobj
    }
    
    function neon(){
    
    //Change all letters to base color
    if (n==0){
    for (m=0;m<message.length;m++)
    //eval("document.all.neonlight"+m).style.color=neonbasecolor
    crossref(m).style.color=neonbasecolor
    }
    
    //cycle through and change individual letters to neon color
    crossref(n).style.color=neontextcolor
    
    if (n<message.length-1)
    n++
    else{
    n=0
    clearInterval(flashing)
    setTimeout("beginneon()",1500)
    return
    }
    }
    
    function beginneon(){
    if (document.all||document.getElementById)
    flashing=setInterval("neon()",flashspeed)
    }
    beginneon()
    
    
    </script>
    </h2>
    
    <p align="center">This free script provided by<br />
    <a href="http://javascriptkit.com">JavaScript Kit</a></p>
    HTML:

     
    piri00, Apr 17, 2010 IP
  2. nwk

    nwk Well-Known Member

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    158
    #2
    What is the problem? Without the problem, can't be of much help..
     
    nwk, Apr 17, 2010 IP
  3. carfanatic01

    carfanatic01 Peon

    Messages:
    239
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I see you posted this, your problem must be in this code.. But please dont give us a hard time looking for it..
     
    carfanatic01, Apr 17, 2010 IP
  4. piri00

    piri00 Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Code is fine but does just one colour highlight.
    I wish to make this code to make two colour highlight (first one colour and then second colour and keep repeating again)

    thanks
     
    piri00, Apr 17, 2010 IP
  5. TomDeLonge

    TomDeLonge Peon

    Messages:
    119
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <script>
    var message="Welcome to JavaScript Kit!"
    var neonbasecolor="gray"
    var neontextcolor1="yellow"
    var neontextcolor2="red"
    var flashspeed=100 //in milliseconds

    ///No need to edit below this line/////

    var n=0
    var neontextcolor=neontextcolor1

    if (document.all||document.getElementById){
    document.write('')
    for (m=0;m<message.length;m++)
    document.write('<span id="neonlight'+m+'">'+message.charAt(m)+'</span>')
    document.write('')
    }
    else
    document.write(message)

    function crossref(number){
    var crossobj=document.all? eval("document.all.neonlight"+number) : document.getElementById("neonlight"+number)
    return crossobj
    }

    function neon(){

    //Change all letters to base color
    if (n==0){
    for (m=0;m<message.length;m++)
    //eval("document.all.neonlight"+m).style.color=neonbasecolor
    crossref(m).style.color=neonbasecolor
    }

    //cycle through and change individual letters to neon color
    crossref(n).style.color=neontextcolor

    if (n<message.length-1)
    n++
    else{
    n=0
    clearInterval(flashing)
    setTimeout("beginneon()",1500)
    return
    }
    }

    function beginneon(){
    neontextcolor = (neontextcolor==neontextcolor1) ? neontextcolor2 : neontextcolor1;
    if (document.all||document.getElementById)
    flashing=setInterval("neon()",flashspeed)
    }
    beginneon()


    </script>
    </h2>

    <p align="center">This free script provided by<br />
    <a href="http://javascriptkit.com">JavaScript Kit</a></p>
     
    TomDeLonge, Apr 20, 2010 IP
  6. piri00

    piri00 Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Great work and help :)
    thanks again
     
    piri00, Apr 21, 2010 IP
  7. TomDeLonge

    TomDeLonge Peon

    Messages:
    119
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You are welcome.
    I am glad that i could help. You can give me a positive feedback by clicking on a start under my post ;)
     
    TomDeLonge, Apr 21, 2010 IP
    nwk likes this.
  8. nwk

    nwk Well-Known Member

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    158
    #8
    Don't attract the mods. ;)...
     
    nwk, Apr 21, 2010 IP