Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  24] [ 6]  / answers: 1 / hits: 9466  / 11 Years ago, mon, february 3, 2014, 12:00:00

I have the following problem and I have not found a way to solve it. I'm using a dynamically generated table, which consists of 4 columns: a checkbox, text values ​​and a hidden input.



echo <tr><td><div class='input-containerh'><input type='checkbox'></div></td>;
echo <td> .$s. </td>;
echo <td> .$L. and some vars............ </td>;
echo <td><input type='hidden' value= . some vars.... ></td>;
echo </tr>;


As I want to format the checkbox, because in some browsers the cell makes me too big, I use a DIV to format input (checkbox) and it works good for me.



Now the problem is a javascript function that detect if the input was select and now does not work me:



function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for(var i=1; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}


Using firebug I found that the problem was:



var chkbox = row.cells[0].childNodes[0];


because it refers to DIV not at input.



How i can reach the input element that is within DIV and also inside the cell?



Thanks for help.


More From » html

 Answers
8

Since the var chkbox = row.cells[0].childNodes[0] worked with this HTML:



<tr><td><input> type='checkbox'></td>


changing the HTML as follows:



<tr><td><div class='input-containerh'><input> type='checkbox'></div></td>


means that row.cells[0].childNodes[0] will now point to the div element. To get the input element inside div, you just access the next level of children with childNodes. So, in a nutshell, you can get access to your input with this:



var chkbox = row.cells[0].childNodes[0].childNodes[0];

[#48102] Monday, February 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;