Ayan Aman Ayan Aman - 1 year ago 55
Ajax Question

Pass the value of checkbox via ajax, php, jquery

Good day. guys i got a problem.
I need to send my checkbox value via ajax to a php file

My question
i want to pass the value in both cases whenever it is check or not.
if it is checked then it should have pass the


and if it is not check then simply the value in content should be passed. via ajax jquery


i know code in jquery (AJAX) file should be updated with
if condition
but i don't know how to do it

Update -----

I have fix the issue of check conditon by following answers


in wallajax.php file when i use

then i am getting te value of content via ajax and it is also returing its value in page

but when i am using
if(isset($_POST["content"]) && isset($_POST["check"]) )

no value is retrieved as a result no return value showing on page

i cant understand, where is the problem happeing, is it on ajax script or wallajax.php file

my code.

<script type="text/javascript">
$(function() {

$("#px").click(function() {
var status2 = $("#status2").val();
var checkit= $("#checkit").is(':checked');
var dataString = 'content=' + status2 + '&check=' + checkit;
type: "POST",
url: "wallajax.php",
data: dataString,
cache: false,
success: function(resol) {
}); return false;



if(isset($_POST["content"]) && isset($_POST["check"]) )
---fetched value------feed value in databse------


<textarea name="content" id="status2"></textarea>
<input name="check" id="checkit" type="checkbox" value="true">check it</input>
<div id="px">Post</div>

Answer Source

Instead of






I would suggest

var data = {'content': status2, 'check': checkit};

instead of

var dataString = 'content=' + status2 + '&check=' + checkit;