javascript - How to get the Value of a checkbox from JQuery? -


i have checkboxes , want add value jquery. have been able retrieve value gets every checkbox value .each jquery command. wasn't sure how value of specific checkbox checked can use append command display data.

the checkbox:

<input id="add_policies_checkbox<?php echo $row[toolid]; ?>" type="checkbox" value=<?php echo $row[toolid]; ?> /> 

the button submits form jquery handle:

<input type="button" name="action" class="btn btn-success checkboxadd" value="add policy" />  

jquery - not sure how information (value) add_policies_checkbox checked:

$(".checkboxadd").click(function(){                     $('[id*="add_policies_checkbox"]').each(function(){                       //alert(this.value);                       var data=this.value;                       $("#div_to_add_this_checkbox_value").append("info added"+data);                     }); });//end ajaxifypolicies 

use [id^="add_policies_checkbox"] selector loop on checkboxes id starting add_policies_checkbox , check checked property

$(".checkboxadd").click(function(){                      $('[id^="add_policies_checkbox"]').each(function(i, v){                        //alert(this.value);                        if($(v).prop('checked')){                        var data=$(v).val();                        $("#div_to_add_this_checkbox_value").append("info added"+data);}                      });  });//end ajaxifypolicies
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="checkbox" value="something1" id="add_policies_checkbox1"/>  <input type="checkbox" value="something2" id="add_policies_checkbox2"/>  <input type="checkbox" value="something3" id="add_policies_checkbox3"/>  <button class="checkboxadd">submit</button>  <div id="div_to_add_this_checkbox_value"></div>


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -