Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  166] [ 6]  / answers: 1 / hits: 23063  / 9 Years ago, fri, june 12, 2015, 12:00:00

How can I get value of checkbox in table? I want use it for in this case in order get parameter. Now, please see html table:



<table id=div_func class=table table-bordered style=width: 100%>
<thead>
<tr>
<th>
<input type=checkbox id=chk_all /></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td> <input type=checkbox class=checkbox1 id=chk name=check[] value=D01 /></td>
<td>Banana </td>
</tr>
<tr>
<td> <input type=checkbox class=checkbox1 id=chk name=check[] value=D02 /></td>
<td>Orange </td>
</tr>
<tr>
<td> <input type=checkbox class=checkbox1 id=chk name=check[] value=D03 /></td>
<td>Apple </td>
</tr>
</tbody>
</table>


And this is my script , I use for get value in checkbox , then put parameter



function add_funcgroup() {
var func_group = [];
var chk_allow = ;
var table = document.getElementById(div_func);
for (var i = 0; i < table.rows.length; i++) {
if ($('#chk')[i].is(':checked')) {
chk_allow = True;
}
else {
chk_allow = False;
}
var group_func = {
GROUP_MOD_ID: id_temp,
FUNCTION_MOD_ID: $('#chk')[i].val(),
ALLOW: chk_allow
};
func_group[i] = group_func;
}

var func_group_temp = {
FUNC_MOD: func_group
};

var DTO = {
'func_group_temp': func_group_temp
};
$.ajax(
{


And it's not working.


More From » jquery

 Answers
9

What you have done is right, but you are not outputting it to the table!



var table = $(#div_func);
var value_check = ;
for (var i = 1; i < table.rows.length; i++) {
if ($('#chk')[i].is(':checked')) {
value_check += i + : + $('#chk')[i].val();
}
}
alert(value_check);


And you aren't appending it, instead saving!


[#66229] Wednesday, June 10, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blair

Total Points: 384
Total Questions: 108
Total Answers: 86

Location: Northern Ireland
Member since Tue, May 5, 2020
4 Years ago
;