Hi Guys, I want to submit form by checkbox checked with silent mode. I have the form as following, <div id="question1"> <form action="<?php echo $submit); ?>" method="post" id="options1" onsubmit="processForm();return true;"> <input type="checkbox" name="agree" value="1" checked="checked" onchange="if(this.checked) this.processForm() ? $('#confirm_').css('display','block') : $('#confirm_').css('display','none');" id="agree" /><label for="agree">Agree</label> <?php } else { ?> <input type="checkbox" name="agree" value="1" onclick="if(this.checked) this.processForm() ? $('#confirm_').css('display','block') : $('#confirm_').css('display','none');" id="agree" /><label for="agree">Agree</label> <?php } ?> </form> </div> PHP: Below are the javascript/ajax <script type="text/javascript"> <!-- $('#confirm').load('index.php?p=form/confirm'); --> </script> <script type="text/javascript"> jQuery("#confirm_").click(function() { var formData = jQuery("#guest").serialize(); //function processForm() { jQuery.ajax( { type: 'POST', url: '<?php echo $submit); ?>', data: '<?php $data); ?>', success: function(data) { $('#message').html(data); } } ); } </script> Code (markup): the issues of these are 1. if checkbox checked that seem no submitted the form to jquery, seems no relations. 2. div section of <div id="question1"> Code (markup): does't hiding 3. div section of <div id="confirm_" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>"> <div id="confirm"></div> </div> PHP: not show... I really needed some helps and pointers form You Guys, I really appreciate every suggestions and many thanks.
You honestly got this javascript idea all wrong... First bug : onsubmit="processForm();return true;" That means that it will submit the form , so it isn't silent anymore... 2nd bug , from what I see in your code : <?php $data); ?> actually 3 bugs here : 1.Either echo / = $data; 2.remove the ) before the ; 3.You did not mention the name of the post variable.Meaning that if you read the variable in php as $_POST['variable_name'] in your ajax request the data section should look like : data : { 'variable_name' : variable_value } where usually variable_values is a javascript variable , meaning that the data you want to send should be stored like : var variable_value = "'"+<?php echo $data; ?>+"'"; If you would have posted the full code I would probably be able to help more...
Well then post and tell people that are trying to help you that it is solved and the solution that worked for you , maybe other people need it as well and want to learn from it....