Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
How i can get value of checkbox in table , I want use for in this case in order get parameter.Now , please see html table

HTML
<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 in array

JavaScript
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(
              {
                  type: "POST",
                  url: "../BUS/WebService.asmx/ADDFUNCTIONGROUP",
                  data: JSON.stringify(DTO),
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (data) {


But it's not work . error
HTML
Uncaught TypeError: $(...)[i].is is not a function
Posted

1 solution

Your bug is more than apparent. This "HTML" code is not valid HTML. The reason is: all values of all id attributes should be unique. If they are not unique, the page will be rendered, but the use of this attribute can give you unpredictable results.

If you support unique value of this attribute, you can get the HTML elements using it, the way you already do.

I do understand that you are trying to do some action on the whole set of elements. Of course, you can do it, and it would be a very typical use of jQuery, only you need to use some other selectors, not id selectors. Please see:
http://api.jquery.com/category/selectors[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900