Web Analytics Made Easy -
StatCounter Random image alt tag - CodingForum

Announcement

Collapse
No announcement yet.

Random image alt tag

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random image alt tag

    Hey guys,

    I have the following script in my page, and it works fine - giving me a random image when the page is refreshed. However, I was just wondering how you manage to put alt tags in so that when you hold the mouse over the picture it gives the comment box description?

    <SCRIPT>
    {img=new Array()
    img[0]="../../../Images/XFiles/seasonone/pilotepisode/ash.JPG"
    img[1]="../../../Images/XFiles/seasonone/pilotepisode/wrstwtch.JPG"
    img[2]="../../../Images/XFiles/seasonone/pilotepisode/bmwtn.JPG"
    img[3]="../../../Images/XFiles/seasonone/pilotepisode/marks.JPG"
    img[4]="../../../Images/XFiles/seasonone/pilotepisode/corpse.JPG"
    img[5]="../../../Images/XFiles/seasonone/pilotepisode/device.JPG"
    img[6]="../../../Images/XFiles/seasonone/pilotepisode/devicere.JPG"
    img[7]="../../../Images/XFiles/seasonone/pilotepisode/graves.JPG"
    img[8]="../../../Images/XFiles/seasonone/pilotepisode/swenson.JPG"
    img[9]="../../../Images/XFiles/seasonone/pilotepisode/nosebled.JPG"
    img[10]="../../../Images/XFiles/seasonone/pilotepisode/exam.JPG"

    mrnd = Math.floor(Math.random() * img.length)

    document.writeln('<IMG SRC="'+img[mrnd]+'">')}
    </SCRIPT>

    thanks

    Mxx
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

  • #2
    Re: Random image alt tag

    document.writeln('<IMG SRC="'+img[mrnd]+'" ALT="'+img[mrnd]+'" >')}

    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

    Comment


    • #3
      Just make a second array...

      Code:
      alts=new array()
      alts[0]="ash"
      alts[1]="wrstwtch"
      .....
      alts[10]="exam"
      and then for the document.write
      Code:
      document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]'">')
      If unclear where to put everthing, tell me and I will post hte whle code

      Comment


      • #4
        alts=new Array()

        Comment


        • #5
          Oooops.....

          Comment


          • #6
            thanks very much guys...and, yes, I am unclear where to put the alts aspect of the code!

            grrr.

            Mxx
            "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

            Comment


            • #7
              Ok, here is the ENTIRE code....

              Code:
              <SCRIPT> 
              {img=new Array() 
              img[0]="../../../Images/XFiles/seasonone/pilotepisode/ash.JPG" 
              img[1]="../../../Images/XFiles/seasonone/pilotepisode/wrstwtch.JPG" 
              img[2]="../../../Images/XFiles/seasonone/pilotepisode/bmwtn.JPG" 
              img[3]="../../../Images/XFiles/seasonone/pilotepisode/marks.JPG" 
              img[4]="../../../Images/XFiles/seasonone/pilotepisode/corpse.JPG" 
              img[5]="../../../Images/XFiles/seasonone/pilotepisode/device.JPG" 
              img[6]="../../../Images/XFiles/seasonone/pilotepisode/devicere.JPG" 
              img[7]="../../../Images/XFiles/seasonone/pilotepisode/graves.JPG" 
              img[8]="../../../Images/XFiles/seasonone/pilotepisode/swenson.JPG" 
              img[9]="../../../Images/XFiles/seasonone/pilotepisode/nosebled.JPG" 
              img[10]="../../../Images/XFiles/seasonone/pilotepisode/exam.JPG" 
              
              alts=new Array()
              alts[0]="whatever you want"
              alts[1]="whatever you want"
              alts[2]="whatever you want"
              alts[3]="whatever you want"
              alts[4]="whatever you want"
              alts[5]="whatever you want"
              alts[6]="whatever you want"
              alts[7]="whatever you want"
              alts[8]="whatever you want"
              alts[9]="whatever you want"
              alts[10]="whatever you want"
              
              
              mrnd = Math.floor(Math.random() * img.length) 
              
              
              document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]'">')}
              
              </SCRIPT>
              There... I hope it helps

              Comment


              • #8
                Thanks cloudski - however, that doesn't seem to be working. No image is showing up at all.

                And I've no idea why - could it be this part?

                alt="'+alts[mrnd]

                should [mrnd] be there?

                Mxx
                "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

                Comment


                • #9
                  Panic over - it was missing a '+' symbol is all.

                  Thanks for all your help, now back to the grindstone!

                  Mxx
                  "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

                  Comment


                  • #10
                    And I've no idea why - could it be this part?

                    alt="'+alts[mrnd]
                    Oh Sorry... ir is supposed to be
                    document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]+'">')}

                    Thats what I get for not double checking my code...

                    Comment


                    • #11
                      Unless you like typing...

                      Code:
                      <script type="text/javascript">
                      
                      var imgPath = '../../../Images/XFiles/seasonone/pilotepisode/';
                      var img = new Array( 
                      'ash.JPG' ,
                      'wrstwtch.JPG' ,
                      'bmwtn.JPG' ,
                      'marks.JPG' ,
                      'corpse.JPG' ,
                      'device.JPG' ,
                      'devicere.JPG' ,
                      'graves.JPG' ,
                      'swenson.JPG' ,
                      'nosebled.JPG' ,
                      'exam.JPG'
                      );
                      
                      var alts = new Array(
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want' ,
                      'whatever you want'
                      );
                      
                      var mrnd = Math.floor(Math.random() * img.length);
                      document.writeln('<img border="0" src="' + imgPath + img[mrnd] + '" alt="' + alts[mrnd] + '">');
                      
                      </script>
                      Last edited by adios; Jul 10, 2002, 06:42 PM.

                      Comment


                      • #12
                        Ya.. I guess tha would work too

                        I was simply posting to the way he has it, since he already has the img Array built that way

                        Comment

                        Working...
                        X