Thursday, 15 September 2011

php - What is the proper way to use JQuery to set and unset Session variables when a user checks a checbox? -



php - What is the proper way to use JQuery to set and unset Session variables when a user checks a checbox? -

i have form , jquery post method set session variable when user checks checkbox.

my question: there straight forwards way unset session variable if user returns , decides uncheck checked box?

html

<?php session_start() ?> <html> <head> <script type="text/javascript"> $(document).ready(function(){ var checkboxes = $(".chkbx").change(function() { var allischecked = checkboxes.length === checkboxes.filter(":checked").length; all[0].checked = allischecked; enablemyelement(checkboxes.filter(":checked").length > 0); putinsession($(this).val()); }); var = $("#checkall").change(function() { checkboxes.attr("checked",this.checked); enablemyelement(this.checked); }); $("#myform").change( function () { $.post( 'actions.php', $(this).serialize(), function(data){ $("#results").html(data) } ); homecoming false; }); }); </script> </head> <body> <form id="myform"> <input id="checkall" type="checkbox"> <input class="chkbx" type="checkbox" value="360" name="box1"> <input class="chkbx" type="checkbox" value="500" name="box2"> <input class="chkbx" type="checkbox" value="510" name="box3"> <input type="submit" value"send" /> </form> <div id="results">will go here</div> <?php print_r($_session); ?> </body> </html>

processing script

<?php session_start(); $post = $_post; foreach ($post $key => $value) { echo $key. "->" .$value; $_session[$key] = $key; } ?>

yes. pass in state of checkbox (checked, unchecked) jquery post. in processing script can check if checked , set/unset $_session variables.

if($_post['checked']) { // current foreach loop } else { unset($_session); }

php jquery session

No comments:

Post a Comment