Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2008, 04:27 PM   PM User | #1
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
Unhappy Alt Attribute in Image Array

I would like to add an "Alt Attribute" to each image.
All images on the page apper in the same spot (like a gallery) so one replaces the other;
using the function:


function rightImage(theImage){

if(imageNum>19){
imageNum=-1}

theImage.src=myImage[imageNum+1];
imageNum++


}

I tried adding alt to the array:

myImage= new Array(20)

myImage[0]="images/copyRight_f001.jpg"
myimage[0].setAttribute('alt','tuna with mango');
myImage[1]="images/copyRight_f002.jpg"
myimage[1].setAttribute('alt','scallop ceviche');
...
but then page gives an error



the page and source can be viewed at www.sashagitin.com/food
Thank you very much for your help.

Last edited by infisoul; 08-29-2008 at 04:31 PM..
infisoul is offline   Reply With Quote
Old 08-29-2008, 04:56 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
myImage[0]="images/copyRight_f001.jpg"
myimage[0].setAttribute('alt','tuna with mango');
myImage[1]="images/copyRight_f002.jpg"
myimage[1].setAttribute('alt','scallop ceviche');
Neither the above code nor the error specified is visible to me in the page given above.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
infisoul (08-29-2008)
Old 08-29-2008, 05:20 PM   PM User | #3
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
Question

sorry here is the page with error:
http://sashagitin.com/beta/food/indexTest.html

it's a bit confusing. Because it interacts with another function that plays the gif animation while image is loading.

so when array doesn't include "alt" it workes fine
myImage[0]="images/copyRight_f001.jpg"

but with alt
myimage[0].setAttribute('alt','tuna with mango');

it doesn't display the image and freezes at gif animation

thanks
infisoul is offline   Reply With Quote
Old 08-30-2008, 06:33 AM   PM User | #4
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
JS is case-sensitive. myimage is different from myImage.

Hope that makes sense.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 08-31-2008, 03:47 AM   PM User | #5
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
Question

Thank you rangana for noticing the case... i changed it but.... it still doesn't work....

Would anyone have a sample of the whole page where alt attribute in the image is assigned by Javascript?
Million Thanks.
infisoul is offline   Reply With Quote
Old 08-31-2008, 03:50 AM   PM User | #6
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
Also I have a SEO question on the same topic. Does google or other engines read Alt text assigned to the image in javascript ???
infisoul is offline   Reply With Quote
Old 08-31-2008, 06:18 AM   PM User | #7
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Have you updated your page already? It seemed that I (still) see the typo:
Code:
myimage[0].setAttribute('alt','tuna with mango');
myImage[1]="images/copyRight_f002.jpg"
myimage[1].setAttribute('alt','scallop ceviche');
Change highlighted to myImage.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 08-31-2008, 06:30 AM   PM User | #8
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by infisoul View Post
Thank you rangana for noticing the case... i changed it but.... it still doesn't work....

Would anyone have a sample of the whole page where alt attribute in the image is assigned by Javascript?
Million Thanks.
you have few errors in javascript:
Code:
myImage[0]="images/copyRight_f001.jpg"
myimage[0].setAttribute('alt','tuna with mango');
myImage[1]="images/copyRight_f002.jpg"
myimage[1].setAttribute('alt','scallop ceviche');
imageNum = 19; must be in code before first place where you use it, more exactly all declaration including myImage.

your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.

best regards

Last edited by oesxyl; 08-31-2008 at 06:38 AM..
oesxyl is offline   Reply With Quote
Old 09-01-2008, 04:49 PM   PM User | #9
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
different solution

setAttribute('alt','text');
Simply didn't work ( and i did change case)

however what worked was a separate array
imageNum=0


myAlt= new Array(20)

myAlt[0]="tuna1"
myAlt[1]="scallop2"
myAlt[2]="tuna3"
myAlt[3]="shrooms"
myAlt[4]="tofu"
myAlt[5]="radish"

and just one more line added to the function
theImage.src=myImage[imageNum+1];
theImage.alt=myAlt[imageNum+1];

sample can be seen in source http://www.sashagitin.com/beta/food/codeTest.html

alt text changes on main image when arrow is used.

However after testing in with Linxs and other SEO tools it turned out that Alt Text in Javascript is OBSOLUTELY USELESS. Google bot simply doesn't see it.
infisoul is offline   Reply With Quote
Old 09-01-2008, 04:57 PM   PM User | #10
infisoul
New Coder

 
Join Date: Aug 2008
Location: Brooklyn
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
infisoul is an unknown quantity at this point
oesxyl : you wrote: your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.
Any source that is not 10 years old suggests that google bot has no problem with nested tables. PLEASE prove sopportive evedance. is you know otherwise

My problem is that the whole website is only visual and any actual text will desturb prospects from viewing the images. In the eyes of google the site is almost empty. Thats why i am trying to create alt text. However creating alt text in javascript did not help. ...
infisoul is offline   Reply With Quote
Old 09-01-2008, 07:09 PM   PM User | #11
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by infisoul View Post
oesxyl : you wrote: your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.
Any source that is not 10 years old suggests that google bot has no problem with nested tables. PLEASE prove sopportive evedance. is you know otherwise
prove me that this is more readable:
Code:
<table>
  <tr>
    <td>
       <table>
          <tr>
             <td>
               <table>
                  <tr>
                    <td>
                      <table>
                         <tr>
                           <td>
                              <table>
                                 <tr>
                                    <td>
                                       <img ....
then this:
Code:
<div>
   <img.....
there are a lot of arguments seo and non-seo against this.

Quote:
My problem is that the whole website is only visual and any actual text will desturb prospects from viewing the images. In the eyes of google the site is almost empty. Thats why i am trying to create alt text. However creating alt text in javascript did not help. ...
is visual because your thinking is visual, , google have google image bot and you can make your gallery more bot friendly and overall is a matter of proper design.

Code:
<div id="p1" class="dh">
   <img src="p1.jpg" alt="p1 alt" title="p1 title" />
</div>
<div id="p2" class="dh">
   <img src="p2.jpg" alt="p1 alt" title="p1 title" />
</div>
Code:
.dh { display: none; }
and then you can use javascript to make #p1 display: block when the page is loading and as far as the user click of one of the buttons to navigate, you change none to block and block to none to display each image.

best regards
oesxyl is offline   Reply With Quote
Old 09-03-2008, 01:51 AM   PM User | #12
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
If I may butt in...

The alternate text attribute is not meant for SEO anyway, it's there for accessibility reasons-- although SEO and accessibility are not mutually exclusive. But considering that robots' reading of alt text is already a bit iffy, it's a lot less likely that javascript-generated alt text will be of help where SEO is concerned.

+1 on oesxyl's hidden content solution. Cheers!

Last edited by Samhain13; 09-03-2008 at 01:54 AM..
Samhain13 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 PM.


Advertisement
Log in to turn off these ads.