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 02-09-2010, 06:11 PM   PM User | #1
PeteWild
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
PeteWild is an unknown quantity at this point
Help needed extracting title from td please

Hi,

I'm pretty new to Javascript, by about two weeks, I'm looking for help with a problem I have with the following....

<td title='text1;text2;text3'>text4</td></tr>

I'm trying to display text1-3 in a table cell on a rotation, I have this to count through the cells to get to the relevent one...

[CODE]
function rotateCell() {
var delayed = document.getElementsByTagName('td'); //.title.split(';');
for (var i=24;i<24;i++)
[CODE]

This should allow me to identify the location/cell 24 but can some one tell me how I then extract the tittle data and have them alternate within the cell?

I'm not allowed to edit the HTML.

Very gratefull for any help

PeteW
PeteWild is offline   Reply With Quote
Old 02-09-2010, 06:31 PM   PM User | #2
Jazzo
Regular Coder

 
Jazzo's Avatar
 
Join Date: Apr 2008
Location: New York City
Posts: 164
Thanks: 20
Thanked 2 Times in 2 Posts
Jazzo is an unknown quantity at this point
Well, document.getElementsByTagName returns a nodelist, which you can ennumerate using a for loop. I'd suggest something like this:

Code:
var delayed = document.getElementsByTagName('td'),
i,
delayedTitle;
for (i = 0; i < delayed.length; i += 1) {
  delayedTitle = delayed[i].getAttribute('title');
  // delayedTitle now refers to the value of the title attribute for each td tag
}
Hope this helps,
Julian
__________________
~Julian
14 y/o web developer, drummer, and Bridge player
Jazzo is offline   Reply With Quote
Old 02-09-2010, 06:39 PM   PM User | #3
PeteWild
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
PeteWild is an unknown quantity at this point
Jazzo

Thanks for posting, ill give that a try once I get home

Pete
PeteWild is offline   Reply With Quote
Old 02-09-2010, 09:19 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I don't see how that helps him with the "rotation" part.

He still has to rotate through the individual chunks of the title, separated by semicolons. But he doesnt' say WHEN or on what basis he needs to do the rotation. Once a second? Each time the page is refreshed? When the user clicks on it???

More info, Sir Wild.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-10-2010, 11:15 AM   PM User | #5
PeteWild
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
PeteWild is an unknown quantity at this point
Hiya,

OP, thanks for coming in on this, the function is on load regulated by interval3 below...

[CODE]
function ol(){
interval = setInterval(twicely,1000);
time = setTimeout('realTime()',500);
interval2 = setInterval(lingo,5000);
interval3 = setInterval(rotateCell,2000);
}
[CODE]

So at this point every two seconds is fine and I can adjust to suit depending on how the effect looks when it runs. This way works quite well with the other functions but I was wondering if it would be two seconds between rotation of the text or is it two seconds between each execution of rotateCell()?

The idea being that every two seconds it should rotate, text1, text2, text3. In the HTML, text 4 (the table data itself) is a duplication of text 1 so reverting back to the original table data is not needed. All the action for this occurs in td 24, so I need to identify that cell too, thats why I started and finished my original for loop at 24 instead of delayed.length, I'm assuming that would work however I'm still learning and could be waaaaay off.

The page itself doesn't consist of any user interaction so display only. I hope thats a bit clearer.

Jazzo, on your code the first line consists of (td),i,delayedTitle; sorry to appear a bit dumb but the comma's are confusing me, is that the the right syntax?

Thanks again guys, appreciate the help!

PeteW

Last edited by PeteWild; 02-10-2010 at 11:34 AM..
PeteWild is offline   Reply With Quote
Old 02-10-2010, 05:57 PM   PM User | #6
PeteWild
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
PeteWild is an unknown quantity at this point
All sorted, thanks to the posters for your help

PeteW
PeteWild 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 01:16 PM.


Advertisement
Log in to turn off these ads.