Reputation: 89
I have a condition that i have to post the different values of checkbox to page2.php as well as display the value on same page. How do i do?
Page1:
<form method="post" action="">
<input name="date1" type="checkbox" value="" id="1" />
<input name="date2" type="checkbox" value="" id="2"/>
</form>
$.ajax({
type: 'POST',
url: 'page2.php',
data: data,
success:function(html){
}
});
Page2:
<?php
$date1 = POST_['date1'];
$date2 = POST_['date2'];
echo $date1;
echo $date2;
?>
Upvotes: 0
Views: 3008
Reputation: 1509
page.php
<?php
$date['date1'] = $_post['date1'];
$date['date2'] = $_post['date2'];
echo $date
?>
Another page
<form method="post" action="">
<input name="date1" type="checkbox" value="" id="1" />
<input name="date2" type="checkbox" value="" id="2"/>
</form>
$.ajax({
type: 'POST',
url: 'page2.php',
data: data,
success:function(html){
alert(html[0]);
alert(html[1]);
}
});
Note: alert(html[0]);
alert(html[1]);
you can put this values anywhere
Upvotes: 0
Reputation: 1093
I'm guessing the second "Page1" is actually Page2
There you have an error, it should be $_POST['date1']. And as commented, you may first check if it is set with:
if (isset($_POST['date1']))
And in you Page1, lets add a container like
<div id="result"></div>
Then inside <script></script>
:
$(function(){
$('input').click(function() {
$.ajax({
type: 'POST',
url: 'PAGE.php',
data: $('form').serialize(),
success:function(html){
$('#result').html(html);
}
});
});
});
This sets the returning result from page2.php inside the element with id "result"
Edit: Here is a JsFiddle: http://jsfiddle.net/rF4qg/
In the one you commented there was some errors with closing braces. See that I've added a name to the checkboxes and that the data sent is formed by serializing the form.
Upvotes: 2