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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder Jazzo's Avatar
    Join Date
    Apr 2008
    Location
    New York City
    Posts
    164
    Thanks
    20
    Thanked 2 Times in 2 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jazzo

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

    Pete

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All sorted, thanks to the posters for your help

    PeteW


  •  

    Posting Permissions

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