html - gettings values from checkbox group with jQuery only works once -


i'm trying build array of values of selected checkboxes in group (i have more 1 checkbox group on page, below 1 of them).

when click on checkbox first alert value of '0' , alert value of '1'. expected. however, when check 2nd checkbox alert no longer shows up. don't see errors in chrome console.

why?

html

    <table id="cphcenter_cblfeatures" class="cblist textbox" style="width:100%;">         <tbody>             <tr>                 <td>                 <input id="cphcenter_cblfeatures_0" type="checkbox" name="ctl00$cphcenter$cblfeatures$0" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$0\',\'\')', 0)" value="6">                 <label for="cphcenter_cblfeatures_0">arbor</label></td>                 <td><input id="cphcenter_cblfeatures_4" type="checkbox" name="ctl00$cphcenter$cblfeatures$4" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$4\',\'\')', 0)" value="7"><label for="cphcenter_cblfeatures_4">disabled access</label></td>             </tr><tr>                 <td><input id="cphcenter_cblfeatures_1" type="checkbox" name="ctl00$cphcenter$cblfeatures$1" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$1\',\'\')', 0)" value="3"><label for="cphcenter_cblfeatures_1">beach</label></td>                 <td><input id="cphcenter_cblfeatures_5" type="checkbox" name="ctl00$cphcenter$cblfeatures$5" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$5\',\'\')', 0)" value="4"><label for="cphcenter_cblfeatures_5">forest</label></td>             </tr><tr>                 <td><input id="cphcenter_cblfeatures_2" type="checkbox" name="ctl00$cphcenter$cblfeatures$2" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$2\',\'\')', 0)" value="1"><label for="cphcenter_cblfeatures_2">bridal suite</label></td>                 <td><input id="cphcenter_cblfeatures_6" type="checkbox" name="ctl00$cphcenter$cblfeatures$6" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$6\',\'\')', 0)" value="2"><label for="cphcenter_cblfeatures_6">garden</label></td>             </tr><tr>                 <td><input id="cphcenter_cblfeatures_3" type="checkbox" name="ctl00$cphcenter$cblfeatures$3" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$3\',\'\')', 0)" value="5"><label for="cphcenter_cblfeatures_3">dancing room</label></td>                 <td><input id="cphcenter_cblfeatures_7" type="checkbox" name="ctl00$cphcenter$cblfeatures$7" onclick="javascript:settimeout('__dopostback(\'ctl00$cphcenter$cblfeatures$7\',\'\')', 0)" value="8"><label for="cphcenter_cblfeatures_7">water</label></td>             </tr>         </tbody>     </table> 

jquery

     function getresults() {                     var arr = new array();          $.each($("input[name*='cblfeatures']:checked"), function () {              arr.push($(this).val());          });           alert(arr.length);          arr = new array();          return true;      }         $(document).ready(function () {          $("#<%=cblfeatures.clientid%>").click(function () { getresults(); });          }); 

it seems me may problem #<%=cblfeatures.clientid%>selector... perhaps try effect:

 $(document).ready( function() {      $("input[name*='cblfeatures']").click(function() { getresults(); });  }); 

here fiddle of functioning way intended: http://jsfiddle.net/tcqwd/

hope helps!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -