mysql - HTML checkbox element not being passed value into jQuery and AJAX string -
i have simple html form few checkboxes. goal here pass info (value of checked boxes) jquery function , input values string passed via ajax php script. here html:
<table class="ui-widget-content" border="0" style="width: 100%;"> <tr> <td width="252px;">pvc's required</td> <td align="left"> <input type="checkbox" id="pvc" name="pvc" value="abc" />abc<br /> <input type="checkbox" id="pvc" name="pvc" value="def" />def<br /> <input type="checkbox" id="pvc" name="pvc" value="ghi" />ghi<br /> <input type="checkbox" id="pvc" name="pvc" value="jkl" />jkl<br /> <input type="checkbox" id="pvc" name="pvc" value="none" />none<br /> </td> </tr> </table>
jquery:
$("#addtechdetails") .button() .click(function(){ var pvc = $("#input[ type= 'checkbox']"); var pvcdata = []; pvc.filter(':checked').each(function(){ pvcdata.push($(this).val()); }) pvc=pvcdata.join(','); //initial info required process form var neworexisting = $("#neworexisting").val(); var numcircuits = $("#numcircuits").val(); var str = "neworexisting="+neworexisting+"&numcircuits="+numcircuits+"&pvc="+pvc; //ajax request $.ajax({ type : "post", cache : false, url : "ajax/addtechdetails.php", info : str, finish : function(xhr, result){ if (result != "success") return; var response = xhr.responsetext; $("#result").html(response); } }) });
output of above next when selections checked: '','','','',
your checkboxes need unique id's:
<input type="checkbox" id="pvc1" name="pvc" value="abc" /> <input type="checkbox" id="pvc2" name="pvc" value="def" /> ...
also, line var pvc = $("#input[ type= 'checkbox']");
should not include leading #
since used identify id (and input
not id).
you utilize 1 of next methods:
$('input[type="checkbox"]:checked').each()
iterates checked elements $('input[name="pvc"]:checked').each()
iterates checkboxes name $('#pvc'+indexofiteration).val()
gets value straight id there more options in docs.
jquery mysql ajax jquery-ui checkbox
No comments:
Post a Comment