PC Review


Reply
Thread Tools Rate Thread

How to alter text inside a table cell using Javascript

 
 
Trevor L.
Guest
Posts: n/a
 
      16th Feb 2005
BlankHello to all the wonderful experts out there.

This may not be strictly a FrontPage question, it is more an HTML/Javascript question,
but I don't know whether there is a more specialised Newsgroup for this type of query.

I have a table like this (there are many more entries)

<table>
<tr>
<td>
<a href="#1"
onclick="... (action) ...">
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
Collage<br>
(mainly<br>
Kate's<br>
Family)
</a>
</td>

........
</tr>
</table>

I have written Javascript to alter the image displayed as follows

function PreLoadThumbs()
{ var ThumbnailsImg = new Array() ;
for (i = 0; i < Thumbnails.length; i++)
{ ThumbnailsImg[i] = new Image() ;
ThumbnailsImg[i].src = Thumbnails[i] ;
document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src; }

(where Thumbnails is a global text array of the thumbnail names
e.g.var Thumbnails = new Array("images/thumbnails/family-pictures.jpg" ,
... ) ;

I would like to be able to do exactly the same for the captions as for the images,
so I have set up an array of caption names
e.g var Captions = new Array("Collage<br>(mainly<br>Kate's<br>Family)" ,
...);

I can put the following code in place of the actual caption and it works
<script type="text/javascript">document.write(Captions[0])</script>

However, I would prefer to do it the same way as the images
i.e. refer to the HTML element and then assign the corresponding element of array Captions to that HTML
something like
document.text["Caption" + (i + 1)] = Captions[i]; }

How do I refer to this element of the HTML?
I am sure I need something other than document.text :-)
--
Thanks,
Trevor L.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 
Reply With Quote
 
 
 
 
Thomas A. Rowe
Guest
Posts: n/a
 
      16th Feb 2005
I think J-Bots has a component that will allow you to associate text with a image on mouse over /
image swapping.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)
http://www.ycoln-resources.com
FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
To assist you in getting the best answers for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp

"Trevor L." <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
BlankHello to all the wonderful experts out there.

This may not be strictly a FrontPage question, it is more an HTML/Javascript question,
but I don't know whether there is a more specialised Newsgroup for this type of query.

I have a table like this (there are many more entries)

<table>
<tr>
<td>
<a href="#1"
onclick="... (action) ...">
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
Collage<br>
(mainly<br>
Kate's<br>
Family)
</a>
</td>

........
</tr>
</table>

I have written Javascript to alter the image displayed as follows

function PreLoadThumbs()
{ var ThumbnailsImg = new Array() ;
for (i = 0; i < Thumbnails.length; i++)
{ ThumbnailsImg[i] = new Image() ;
ThumbnailsImg[i].src = Thumbnails[i] ;
document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src; }

(where Thumbnails is a global text array of the thumbnail names
e.g.var Thumbnails = new Array("images/thumbnails/family-pictures.jpg" ,
... ) ;

I would like to be able to do exactly the same for the captions as for the images,
so I have set up an array of caption names
e.g var Captions = new Array("Collage<br>(mainly<br>Kate's<br>Family)" ,
...);

I can put the following code in place of the actual caption and it works
<script type="text/javascript">document.write(Captions[0])</script>

However, I would prefer to do it the same way as the images
i.e. refer to the HTML element and then assign the corresponding element of array Captions to that
HTML
something like
document.text["Caption" + (i + 1)] = Captions[i]; }

How do I refer to this element of the HTML?
I am sure I need something other than document.text :-)
--
Thanks,
Trevor L.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      16th Feb 2005
Thomas,

Thank you (as always) for your prompt reply.

However, I don't want to associate text with a image on mouse over / image
swapping. I want the text to be there (underneath it) whenever the page is
presented.

I have this HTML
<td>
<a href="#1"
onclick="... (action) ...">
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
GARBAGE TEXT
</a>
</td>

I want GARBAGE TEXT to be replaced by an element of the array Captions which
has been defined in Javascript. I have already done a similar task with the
element src="images/blank.gif" by this code (when i = 0)
document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src;

The line of code above is part of a function PreLoadThumbs() which is called
from the HTML by
<body onload = "PreLoadThumbs()">

So my question is what reference do I use in Javascript to change GARBAGE
TEXT?

Is it document.table["Table" + (i +1)].rows[0].cells[0].text" (where the
table tag has name="Table1" ,etc.)
Or what ?
--
Cheers,
Trevor L.





I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Thomas A. Rowe
Guest
Posts: n/a
 
      16th Feb 2005
Trevor,

Sorry, I misunderstood what you were asking. I can't help you with JavaScript coding.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)
http://www.ycoln-resources.com
FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
To assist you in getting the best answers for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp

"Trevor L." <(E-Mail Removed)> wrote in message
news:%23g8AE9%(E-Mail Removed)...
> Thomas,
>
> Thank you (as always) for your prompt reply.
>
> However, I don't want to associate text with a image on mouse over / image swapping. I want the
> text to be there (underneath it) whenever the page is presented.
>
> I have this HTML
> <td>
> <a href="#1"
> onclick="... (action) ...">
> <img src="images/blank.gif" name="Thumbs1" alt=""><br>
> GARBAGE TEXT
> </a>
> </td>
>
> I want GARBAGE TEXT to be replaced by an element of the array Captions which has been defined in
> Javascript. I have already done a similar task with the element src="images/blank.gif" by this
> code (when i = 0)
> document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src;
>
> The line of code above is part of a function PreLoadThumbs() which is called from the HTML by
> <body onload = "PreLoadThumbs()">
>
> So my question is what reference do I use in Javascript to change GARBAGE TEXT?
>
> Is it document.table["Table" + (i +1)].rows[0].cells[0].text" (where the table tag has
> name="Table1" ,etc.)
> Or what ?
> --
> Cheers,
> Trevor L.
>
>
>
>
>
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
>



 
Reply With Quote
 
Steve Easton
Guest
Posts: n/a
 
      16th Feb 2005
BlankWhat you're looking for is:

document.all.elementname.innerHTML = "The text you want to write";

Where elementname = the id of the element: <td id="elementname"</td>

and "The text you want to write" = the text you want to appear. It can be a variable.

If you want to define a special font or font color it's done as shown below.

document.all.elementname.innerHTML = "<font color=blue>The text you want to write</font>";

hth


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Trevor L." <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Hello to all the wonderful experts out there.

This may not be strictly a FrontPage question, it is more an HTML/Javascript question,
but I don't know whether there is a more specialised Newsgroup for this type of query.

I have a table like this (there are many more entries)

<table>
<tr>
<td>
<a href="#1"
onclick="... (action) ...">
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
Collage<br>
(mainly<br>
Kate's<br>
Family)
</a>
</td>

........
</tr>
</table>

I have written Javascript to alter the image displayed as follows

function PreLoadThumbs()
{ var ThumbnailsImg = new Array() ;
for (i = 0; i < Thumbnails.length; i++)
{ ThumbnailsImg[i] = new Image() ;
ThumbnailsImg[i].src = Thumbnails[i] ;
document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src; }

(where Thumbnails is a global text array of the thumbnail names
e.g.var Thumbnails = new Array("images/thumbnails/family-pictures.jpg" ,
... ) ;

I would like to be able to do exactly the same for the captions as for the images,
so I have set up an array of caption names
e.g var Captions = new Array("Collage<br>(mainly<br>Kate's<br>Family)" ,
...);

I can put the following code in place of the actual caption and it works
<script type="text/javascript">document.write(Captions[0])</script>

However, I would prefer to do it the same way as the images
i.e. refer to the HTML element and then assign the corresponding element of array Captions to that
HTML
something like
document.text["Caption" + (i + 1)] = Captions[i]; }

How do I refer to this element of the HTML?
I am sure I need something other than document.text :-)
--
Thanks,
Trevor L.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Jon Spivey
Guest
Posts: n/a
 
      16th Feb 2005
Hi Trevor,

You'd give the cell an ID then use script like this to set the text.
<script type="text/javascript">
function changeText(a,b){
if(!document.all && !document.getElementById)return;
var c = (document.all)?document.all(a): document.getElementById(a);
if(c)c.innerHTML=b;
}
</script>
<td id="something">this text will change</td>
<a href="javascript:;" onclick="changeText('something', 'some new text');
return false;">change text</a>

--
Cheers,
Jon
Microsoft MVP

"Trevor L." <(E-Mail Removed)> wrote in message
news:%23g8AE9%(E-Mail Removed)...
> Thomas,
>
> Thank you (as always) for your prompt reply.
>
> However, I don't want to associate text with a image on mouse over / image
> swapping. I want the text to be there (underneath it) whenever the page is
> presented.
>
> I have this HTML
> <td>
> <a href="#1"
> onclick="... (action) ...">
> <img src="images/blank.gif" name="Thumbs1" alt=""><br>
> GARBAGE TEXT
> </a>
> </td>
>
> I want GARBAGE TEXT to be replaced by an element of the array Captions
> which has been defined in Javascript. I have already done a similar task
> with the element src="images/blank.gif" by this code (when i = 0)
> document.images["Thumbs" + (i + 1)].src = ThumbnailsImg[i].src;
>
> The line of code above is part of a function PreLoadThumbs() which is
> called from the HTML by
> <body onload = "PreLoadThumbs()">
>
> So my question is what reference do I use in Javascript to change GARBAGE
> TEXT?
>
> Is it document.table["Table" + (i +1)].rows[0].cells[0].text" (where the
> table tag has name="Table1" ,etc.)
> Or what ?
> --
> Cheers,
> Trevor L.
>
>
>
>
>
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
>



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      17th Feb 2005
Thomas,
Thanks for the reply.

Jon,
Thanks. The code you sent is getting closer to what I was looking for, but
it isn't quite there.

My code is
<table>
<tr>
<td id="Text1">
<a href="#1"
onclick="spawnJimcoPopup(.........)"
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
THIS IS THE TEXT I WANT TO CHANGE
</a>
</td>
....

When I run the code you sent (modified to call it from <body onload="...">)
, everything within <td></td> was replaced, so I get the correct text, but
no image.

After a bit of experimentation I used this code
<table>
<tr>
<td>
<a href="#1"
onclick="spawnJimcoPopup(.........)"
<img src="images/blank.gif" name="Thumbs1" alt=""><br>
<span id="Text1">THIS IS THE TEXT I WANT TO CHANGE</span>
</a>
</td>
....

Hooray! It worked.

Does this mean that any tag element in HTML can be given an id and then that
id used in Javascript to refer to it.
It sure looks like it :-)
--
Many Thanks,
Trevor L.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      17th Feb 2005
Hi and thanks.

What I ending up using was

document.getElementById('Text' + (i + 1)).innerHTML= Captions[i];
where Captions is a text array

It works fine, so how does this differ from:
document.all.elementname.innerHTML = "The text you want to write"; ?

What does the ".all" add to the statement?

Thanks for the tip on changing font. Luckily I have a class definition in
force in this division, so the font I wanted was carried through.
--
Cheers,
Trevor L.




I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Jon Spivey
Guest
Posts: n/a
 
      17th Feb 2005
document.all is an IE only method - it's not supported on any other browser.
See my other reply

--
Cheers,
Jon
Microsoft MVP

"Trevor L." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi and thanks.
>
> What I ending up using was
>
> document.getElementById('Text' + (i + 1)).innerHTML= Captions[i];
> where Captions is a text array
>
> It works fine, so how does this differ from:
> document.all.elementname.innerHTML = "The text you want to write"; ?
>
> What does the ".all" add to the statement?
>
> Thanks for the tip on changing font. Luckily I have a class definition in
> force in this division, so the font I wanted was carried through.
> --
> Cheers,
> Trevor L.
>
>
>
>
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
>



 
Reply With Quote
 
 
 
Reply

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alter Text in 900 cell entries =?Utf-8?B?cmF5d29vZA==?= Microsoft Excel Worksheet Functions 2 9th Jul 2007 10:40 PM
Question about ALTER TABLE and ALTER COLUMN BobV Microsoft Access VBA Modules 7 20th Sep 2006 02:06 PM
Javascript code inside a table cell.... Pete Smith Microsoft ASP .NET 1 15th Mar 2006 09:40 AM
Text form field inside WORD table cell, odd selection behavior =?Utf-8?B?cHdyaWNoY3JlZWs=?= Microsoft Word Document Management 1 11th Oct 2005 03:57 PM
how to alter cell format if cell contains text =?Utf-8?B?SGVhdGhlciBhdCBXRU8=?= Microsoft Excel Worksheet Functions 4 28th Jul 2005 07:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.