Get row when checking checkbox in html table -


i have html table checkbox in 1 of columns. want know how row data when user clicks on checkbox javascript (without jquery)? can please me this?

thanks

you try this:

html:

<table>     <thead>         <tr><th></th><th>row text</th></tr>     </thead>     <tr>         <td><input type="checkbox" /></td>         <td>test</td>     </tr>     <tr>         <td><input type="checkbox" /></td>         <td>test 2</td>     </tr>     <tr>         <td><input type="checkbox" /></td>         <td>test 3</td>     </tr> </table> 

javascript:

checkboxes = document.getelementsbytagname("input");   (var = 0; < checkboxes.length; i++) {     var checkbox = checkboxes[i];     checkbox.onclick = function() {         var currentrow = this.parentnode.parentnode;         var secondcolumn = currentrow.getelementsbytagname("td")[1];          alert("my text is: " + secondcolumn.textcontent );     }; }  

jsfiddle: http://jsfiddle.net/markwylde/wzphf/1/


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -