Current location: Hot Scripts Forums » General Web Coding » JavaScript » ALT tag meets JavaScript code.


ALT tag meets JavaScript code.

Reply
  #1 (permalink)  
Old 09-25-06, 05:25 AM
seroxatmad's Avatar
seroxatmad seroxatmad is offline
Newbie Coder
 
Join Date: May 2005
Location: Durham UK.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
ALT tag and Arrays

Hi

I have a script to show a picture description when the mouse on over an image. Can the info in this array be insert into an ALT tag?
Quote:
var blurb = new Array(17); // = number of different options
blurb[1] = "Picture Description for Pic1";
blurb[2] = "Picture Description for Pic2";
blurb[3] = "Picture Description for Pic3";
blurb[4] = "Picture Description for Pic4";
blurb[5] = "Picture Description for Pic5";
blurb[6] = "Picture Description for Pic6";

function seeBlurb(option) {
document.getElementById('blurbDiv').innerHTML = blurb[option];
}
</script>
Regards

John
Reply With Quote
  #2 (permalink)  
Old 09-25-06, 05:52 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

just refer to the item as

document.getElementById('myimage1').alt='your text here';

or you could refer to the image like this

document.getElementById('myimage' + option).alt = blurb[option];

in future post this type of stuff in the javascript section you will probably get a faster response
__________________
Intelligence is not knowledge, but the way we use our knowledge.
Reply With Quote
  #3 (permalink)  
Old 09-25-06, 08:00 AM
seroxatmad's Avatar
seroxatmad seroxatmad is offline
Newbie Coder
 
Join Date: May 2005
Location: Durham UK.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

Thanks for the reply

Quote:
<td><a href="pic2.png" rel="lightbox" title="Optional Text..."><img src="pic2_sml.png" alt="pic2" name="2" width="190" height="96" id="2" style="cursorointer" onmouseover="seeBlurb(2);" /></td>
Can i just add the code you suggest in place of the alt tag in the script above.

A test link is www.thestottfamily.co.uk/template/index.php

Regards

John
Reply With Quote
  #4 (permalink)  
Old 09-25-06, 08:11 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Code:
<html>
<head>
<script>
var blurb = new Array(17); // = number of different options
blurb[1] = "Picture Description for Pic1";
blurb[2] = "Picture Description for Pic2";
blurb[3] = "Picture Description for Pic3";
blurb[4] = "Picture Description for Pic4";
blurb[5] = "Picture Description for Pic5";
blurb[6] = "Picture Description for Pic6";

function seeBlurb(option) {
document.getElementById('blurbDiv').innerHTML = blurb[option];
} 

function loadalt() { 

var i=0;
for(i=0;i<6;i++){
document.getElementById(i).alt = blurb[i];
}

}
</script>
</head
<body onload="loadalt()">
</body>
</html>
This should work fine. Just put your images onto the page.
__________________
Intelligence is not knowledge, but the way we use our knowledge.
Reply With Quote
  #5 (permalink)  
Old 09-25-06, 08:16 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Moved to Javascript.
Reply With Quote
  #6 (permalink)  
Old 09-25-06, 08:16 AM
seroxatmad's Avatar
seroxatmad seroxatmad is offline
Newbie Coder
 
Join Date: May 2005
Location: Durham UK.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
ALT tag meets JavaScript code.

Hi

I have a piece of code that when the mouse is over an image it displays a description of the image.

It would be nice if this description was placed in the images ALT tag.
Code:
 var blurb = new Array(17); // = number of different options 
      blurb[1] = "Picture Description for Pic1"; 
      blurb[2] = "Picture Description for Pic2"; 
      blurb[3] = "Picture Description for Pic3"; 
	  blurb[4] = "Picture Description for Pic4"; 
      blurb[5] = "Picture Description for Pic5"; 
      blurb[6] = "Picture Description for Pic6"; 
	  blurb[7] = "Picture Description for Pic7"; 
      blurb[8] = "Picture Description for Pic8"; 
      blurb[9] = "Picture Description for Pic9"; 
	  blurb[10] = "Picture Description for Pic10";
	  blurb[11] = "Picture Description for Pic11";
	  blurb[12] = "Picture Description for Pic12"; 
	  blurb[13] = "Picture Description for Pic13"; 
	  blurb[14] = "Picture Description for Pic14"; 
	  blurb[15] = "Picture Description for Pic15"; 
	  blurb[16] = "Picture Description for Pic16"; 
	  blurb[17] = "Picture Description for Pic17"; 
      function seeBlurb(option) { 
      document.getElementById('blurbDiv').innerHTML = blurb[option]; 
      }
This is placed in the area i want the description

Quote:
<div id="blurbDiv">
The images are displayed like this, this is were i have the ALT tag:

Code:
<td><a href="pic3.png" rel="lightbox" title="Optional Text..."><img src="pic3_sml.png" alt="pic3" name="3" width="190" height="96" id="3" style="cursor:pointer" onmouseover="seeBlurb(3);" /></td>
So i want the alt=pic3 replacing with the text already in
blurb[3] = "Picture Description for Pic3"; as an example.

Any ideas?

Regards

John

Last edited by nico_swd; 09-25-06 at 08:30 AM.
Reply With Quote
  #7 (permalink)  
Old 09-25-06, 08:30 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Threads merged. Please do not cross post.
Reply With Quote
  #8 (permalink)  
Old 09-25-06, 08:44 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

in that case just change

Code:
function seeBlurb(option) { 
      document.getElementById('blurbDiv').innerHTML = blurb[option]; 
}
to

Code:
function seeBlurb(option) { 
      document.getElementById('blurbDiv').innerHTML = blurb[option]; 
      document.getElementById(option).alt= blurb[option]; 
}
__________________
Intelligence is not knowledge, but the way we use our knowledge.
Reply With Quote
  #9 (permalink)  
Old 09-25-06, 09:09 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Note that the "alt" attribute won't show up on Firefox. I'd rather set the "title" attribute which works on all browsers.
Reply With Quote
  #10 (permalink)  
Old 09-25-06, 09:22 AM
seroxatmad's Avatar
seroxatmad seroxatmad is offline
Newbie Coder
 
Join Date: May 2005
Location: Durham UK.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

Thanks...one extra line of code and it works fine.

I think a book on the subject will be bought soon.

John


P.S I use Firefox and it shows the ALT working when i right click and select properties. I will try title also. Thanks again.

Added both ALt and TITLE - works fine. www.thestottfamily.co.uk/template/index.php

Last edited by seroxatmad; 09-25-06 at 09:33 AM. Reason: Checked code...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
JavaScript inside HTML code Mondler JavaScript 1 11-30-05 08:32 PM
click-once javascript code imagerage Everything Java 1 07-16-05 12:38 AM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM


All times are GMT -5. The time now is 11:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.