?
Solved

Javascript detect row number of table

Posted on 2006-05-24
6
Medium Priority
?
351 Views
Last Modified: 2012-05-05
Is there any way to detect what row in a table that a user clicked on?  I have a table with regular html buttons (<button id="1"> 2,3,4 ect.) in it.  I have a function that deletes the rows from the table when the user clicks on the button.  But after it deletes the row the row numbers change.  Is there anyway to detect what row the button, or anything for that matter, is in so users can delete more than one row?
0
Comment
Question by:johnywhite
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
0h4crying0utloud earned 2000 total points
ID: 16756580

The "this.parentNode.parentNode" return the row obj that contains the button that was clicked. Does that help?

<table>
  <tr id="1strow">
    <td><input type="button" onclick="alert(this.parentNode.parentNode.id)" value="test me"></td>
  </tr>
</table>
0
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 16761282


Did you need more help with this?
0
 

Author Comment

by:johnywhite
ID: 16763103
That doesn't seem to be working it doesn't return anything.  It doesn't give an error either.  Could you post a working page that shows this as an example.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:johnywhite
ID: 16765456
I understand it.  I have to have the row id, however, the deleteRow command only accepts the indexnumber of the row.  Is there anyway to either return the index number or delete a row by it's id?
0
 

Author Comment

by:johnywhite
ID: 16765470
I just figured it out it is this.parentNode.parentNode.rowIndex instead.  Thanks for your help!
0
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 16765556

Yeah, that's right, you dont even need the rowID. Glad to Help!

Cheers!
-Vinson Gracia
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

839 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