[SOLVED] accessing table data

This is a discussion on "[SOLVED] accessing table data" within the JavaScript Forum section. This forum, and the thread "[SOLVED] accessing table data are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Dec 2nd, 2007, 02:10
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] accessing table data

i've been trying to create dynamic links from table data
found this code online

but when i try to copy it to my table it doesn't work
HTML: Select all
<head>
...
<script type="text/javascript">
  function filltableLinks(){
  var audiolink;
  var i;
  for (i=1; i<document.getElementById('lecture1').rows.length; i++)
  {
  audiolink = document.getElementById('lecture1').rows[i].cells[1].childNodes[0].data;
  var link_cell = document.createElement('td');
  var link = document.createElement('a');
  link.setAttribute('href', 'audioplayer.htm/result?audiolink=' + audiolink);
  var image = document.createElement('img');
  image.setAttribute('src', '../miniproject/images/MusicVideo_Icon.png');
  link.appendChild(image);
  link_cell.appendChild(link);
  document.getElementById('lecture1').rows[i].appendChild(link_cell);
  } 
  </script>

<body>
......
<div>
    <table summary="Clip Information">

        <caption>Lecture 1</caption>
        <thead>
            <tr>
                .......
            </tr>
        </thead>
        <tfoot>
            <tr><td> </td></tr>
        </tfoot>
        <tbody id="lecture1" >
            <tr>

                <td><a href="75743899.mp3">Aparnet; Protocol; Internet</a></td>
                <td> 6:23 </td>
            </tr>
            <tr>
        </tbody>
    </table>
</div>
<body>
what's wrong??

Last edited by c010depunkk; Dec 2nd, 2007 at 09:25. Reason: please use [html] tags when posting HTML
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 2nd, 2007, 02:35
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: accessing table data

neither starting the for-loop from i=0
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 2nd, 2007, 02:55
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: accessing table data

not even changing the whole thing to this one
HTML: Select all
for (i=0; i<document.getElementById('lecture1').rows.length; i++)
  {
  audiolink = document.getElementById('lecture1').rows[i].cells[1].childNodes[0].data;
  audiolink = audiolink.split("\"");
  audiolink = audiolink[1];
  var link_cell = document.createElement('td');
  var link = document.createElement('a');
  link.setAttribute('href', 'audioplayer.htm/result?audiolink=' + audiolink);
  var image = document.createElement('img');
  image.setAttribute('src', '../miniproject/images/MusicVideo_Icon.png');
  link.appendChild(image);
  link_cell.appendChild(link);
  document.getElementById('lecture1').rows[i].appendChild(link_cell);
  }

Last edited by c010depunkk; Dec 2nd, 2007 at 09:26. Reason: please use [html] tags when posting HTML
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 2nd, 2007, 04:52
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: accessing table data

i have identified the problem

in the first line of the for-loop
i'm am missing the nod of <a> after cell[0]
what should my script be if i wanna get the href of <a> of the <table>

Thanks!
HTML: Select all
  <script type="text/javascript">
  function filltableLinks(){
  var audiolink;
  var i;
  for (i=0; i<document.getElementById('lecture1').rows.length; i++)
  {
    audiolink = document.getElementById('lecture1').rows[i].cells[0].childNodes[0].data;
    audiolink = audiolink.split('"');
    audiolink = audiolink[1];
    var link_cell = document.createElement('td');
    var link = document.createElement('a');
    link.setAttribute('href', 'audioplayer.htm?audiolink=' + audiolink);
    var image = document.createElement('img');
    image.setAttribute('src', '../miniproject/images/MusicVideo_Icon.png');
    link.appendChild(image);
    link_cell.appendChild(link);
    document.getElementById('lecture1').rows[i].appendChild(link_cell);
  } 
  }
  </script>

<body>
    <table summary="Clip Information">

        <tbody id="lecture1" >
            <tr>

                <td><a href="75743899.mp3">abc</a></td>
                <td> 6:23 </td>
            </tr>
        </tbody>
    </table>
</body>

Last edited by c010depunkk; Dec 2nd, 2007 at 09:26. Reason: please use [html] tags when posting HTML
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 2nd, 2007, 04:55
Junior Member
Join Date: Nov 2007
Location: Hong Kong
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: accessing table data

solved!

replacing:
audiolink = document.getElementById('lecture1').rows[i].cells[1].childNodes[0].data;

with:
audiolink = document.getElementById('lecture1').rows[i].cells[0].innerHTML;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem accessing specific form elements Sagaris JavaScript Forum 4 Sep 23rd, 2007 11:52
how access data from table in php, azeemserver PHP Forum 2 Aug 30th, 2007 11:09
Accessing Data OmiE Starting Out 1 May 9th, 2007 20:22
ACCESS: one table one data,and only one! Monie Databases 1 Aug 2nd, 2004 09:00
ACCESS: one data in one table Monie Classic ASP 1 Aug 2nd, 2004 08:52


All times are GMT. The time now is 01:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42