javascript - How can I pass the value coming from a jQuery variable to PHP? -
the webpage working on has many rows of data checkboxes @ end.
sample is:
so collecting page ids of each row when user checks checkbox.
but how pass collected data jquery php?
so far have following:
jquery:
var collectionofpages = []; (function ( $ ){ $.fn.addcheckbox = function() { $("#submitaddid").on("click", this, function() { alert(collectionofpages); }); $("#addcheckboxes input[type='checkbox']").click(function() { if($(this).prop('checked') == true) { $('#addcheckboxes :checked').each(function() { collectionofpages.push($(this).val()); }); } else { //todo } }); }; })(jquery);
php:
<form name="frmadd" id="addcheckboxform" method="post" action="index.php"> <input type="hidden" name="useridhidden" id="useridhidden"/> <input type="hidden" name="pageshidden" id="pageshidden" /> </form> <table id="checkboxtables" cellpadding="10" cellspacing="1"> <thead> <tr> <th><strong>page id</strong></th> <th><strong>page name</strong></th> <th><strong>action</strong></th> </tr> </thead> <tbody> <tr id="addcheckboxes"> <td><?php echo $row["pageid"]; ?></td> <td><?php echo $row["pagename"]; ?></td> <td><input type="checkbox" name="chkboxadd" $row["pageid"]; ?>">add</td> </tr> </tbody> </table> <button type="button" name="submitadd" id="submitaddid">submit </button>
so pass values coming jquery variable
collectionofpages
to php variable:
$_post['pageshidden]
which created inside
<input type="hidden" name="pageshidden" id="pageshidden" />
thank in advance.
you can use jquery.ajax
$("#submitaddid").on("click", this, function() { $.ajax({ method: "post", url: "some.php", data: { 'collectionofpages': collectionofpages } }); });
Comments
Post a Comment