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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 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
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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"

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    alts=new Array()

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oooops.....

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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; 07-11-2002 at 12:42 AM.

  • #12
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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