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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do i concactinate a identifier?

    firstly this is what I have..
    Code:
    <script type="text/javascript">
    function mouseOver(txt)
    {
      if (txt == "b1")
        document.b1.src ="images/rollbutton.gif"
      if (txt == "b2")
        document.b2.src ="images/rollbutton.gif"
      if (txt == "b3")
        document.b3.src ="images/rollbutton.gif"
      if (txt == "b4")
        document.b4.src ="images/rollbutton.gif"
      if (txt == "b5")
        document.b5.src ="images/rollbutton.gif"
      if (txt == "b6")
        document.b6.src ="images/rollbutton.gif"
      if (txt == "b7")
        document.b7.src ="images/rollbutton.gif"
      if (txt == "b8")
        document.b8.src ="images/rollbutton.gif"
      if (txt == "b9")
        document.b9.src ="images/rollbutton.gif"
      if (txt == "b10")
        document.b10.src ="images/rollbutton.gif"
    }
    function mouseOut(txt)
    {
      if (txt == "b1")
        document.b1.src ="images/b1.PNG"
      if (txt == "b2")
        document.b2.src ="images/b2.PNG"
      if (txt == "b3")
        document.b3.src ="images/b3.PNG"
      if (txt == "b4")
        document.b4.src ="images/b4.PNG"
      if (txt == "b5")
        document.b5.src ="images/b5.PNG"
      if (txt == "b6")
        document.b6.src ="images/b6.PNG"
      if (txt == "b7")
        document.b7.src ="images/b7.PNG"
      if (txt == "b8")
        document.b8.src ="images/b8.PNG"
      if (txt == "b9")
        document.b9.src ="images/b9.PNG"
      if (txt == "b10")
        document.b10.src ="images/b10.PNG"
    }
    </script>
    what I am trying to make it is...
    Code:
    function mouseOver(txt) document.+txt+.src ="images/"+txt+".PNG"
    function mouseOut(txt) document.+txt+.src ="images/rollbutton.gif"
    I mean you see what I want just I have no idea how to pull it off, I just want it to do it by itself to eliminate redundancy, redundancy hurts my eyes

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I presume that 'txt' passes the value of a name attribute, right?

    Code:
    function mouseOver(txt){
    document.getElementsByName(txt)[0].src ='images/rollbutton.gif';
    }
    function mouseOut(txt){
    document.getElementsByName(txt)[0].src ='images/'+txt+'.png';
    }
    But I advise you to use rather id's instead of names, and getElementById(id) instead of getElementsByName(name)[0].
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    well I almost thought it was impossible, takes geniouses like you to prove me wrong Thank you kor! Inoob~~ dis is awesome redundancy NO MORE! my background is in mIRC, I'm jumping into php and javascript, and in mIRC I learned redundancy is retarded, and that lesson follows me everywhere, and now redundancy that I create makes me kinda mad at myself coz I know i cud do better, thanks for all your help kor, you made my day (well morning... 4:24AM here :P)


  •  

    Posting Permissions

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