Solved

How to get  html table's particular column value?

Posted on 2004-10-22
18,455 Views
Last Modified: 2011-08-18
Hi,

I am writing a javascript function to delete a row from a table filled with data. How to get one of the html table's column values so that I can delete the selected row?

Please give answer with code.
0
Question by:limct
    6 Comments
     
    LVL 63

    Accepted Solution

    by:
    Like this:


    <html>
    <head>
    <script>
    function showCells(){
      rows = document.getElementsByTagName("TABLE")[0].rows;
      for(i=0;i<rows.length;i++){
        cells = rows[i].cells;
        for(j=0;j<cells.length;j++){
          alert(i+"-"+j+": "+cells[j].innerHTML);
        }
      }
    }
    </script>
    </head>
    <body>
    <a href="javascript:showCells()">Show</a>
    <table>
    <tr><td>A</td><td>B</td><td>C</td></tr>
    <tr><td>D</td><td>E</td><td>F</td></tr>
    <tr><td>G</td><td>H</td><td>I</td></tr>
    </table>
    </body>
    </html>


    0
     
    LVL 3

    Expert Comment

    by:ragerino
    do you want to delete the rows in the html-table or do you want to do a delete of the data in the background on the server

    if you just want to delete the html-table-row put this td in your table
    --------------------------------------------------------------------------------
    ....
    <td><a href="javascript:void null;" onclick="var e=this;while(e.tagName!='TR'){e=e.parentNode};if(e){e.parentNode.removeChild(e);}">[del]</a></td>
    ....
    --------------------------------------------------------------------------------

    you can also make a function:

    put this to your head
    -------------------------------------------------
    <script type="text/javascript">
    function delRow(e){
      //first find the tablerow
      while(e && e.tagName!='TR')
         e=e.parentNode;
      //if found then remove it form the table (e.parentNode='TBODY')
      if(e)
        e.parentNode.removeChild(e);
    }
    </script>
    --------------------------------------------------------------------------------


    then the tablecell can look like this:
    --------------------------------------------------------------------------------
    ....
    <td><img src="yourdelicon.gif" border=0 style="cursor:pointer;" onclick="delRow(this);"></td>
    ....
    --------------------------------------------------------------------------------

    hope this helps and you give me the points :)
    0
     
    LVL 63

    Expert Comment

    by:Zvonko
    First item in your member profile ragerino is LotusScript. Are you a PCLP?
    0
     
    LVL 63

    Expert Comment

    by:Zvonko
    Thanks for points and grading.

    ragerino, wir sehen uns ;-)
    0
     
    LVL 63

    Expert Comment

    by:Zvonko
    Sorry Alex, I confused your member name with another guy.
    0
     
    LVL 3

    Expert Comment

    by:ragerino
    hehe :)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now