Grab values from checked checkboxes and put them in an array using Javascript/jQuery -
i want values of checked checkboxes name="car_type[]"
, alert final array values. how that? far, have code. it's not working. don't know how loop through checked checkboxes , add values array car_type_arr
. cannot alert final array using alert(car_type_arr);
. help.
$().ready(function(){ $('.prettycheckbox').click(function(e) { e.preventdefault(); var car_type_arr = []; $("input:checkbox[name=car_type]:checked").each(function() { // here need add values array in php // e.g. $car_type_arr[] = $the_grabbed_value; // using javascript syntax // how that? }); // need alert array, how in js? alert(car_type_arr); return false; }); });
try below code:
<input type="checkbox" name="chkbox" value="xxx"> <input type="checkbox" name="chkbox" value="xxx1"> <input type="checkbox" name="chkbox" value="xxx2"> <input type="button" id="btnbox"> $(document).ready(function(){ $("#btnbox").click(function(){ var car_type_arr = []; $("input:checkbox[name=chkbox]:checked").each(function() { car_type_arr.push($(this).val()); alert(car_type_arr); }); }); });
Comments
Post a Comment