jQuery and checkboxes
jQuery and checkboxes
Hello,
I'm making a jQuery script that will use the $.post() function to fetch another php file when a check-box is clicked.
That other php file will perform a query to update my MySQL database and when the query is done it will send back another check-box.
The problem is that when the query is done and the 'new' check-box is shown, well that check-box doesn't respond.
I have this now as code:
jQuery code:
- var checked = "y",
depot = $('span#depot').text(),
date = $('span#date').text(),
tour = $('span#tour').text();
- $('#check').click(function(){
$.post('insertCheckTour.php', ({checked: checked, depot: depot, date: date, tour: tour}), function(data){
$('.checkbox').animate({"opacity": "hide"}, {"duration": "slow"});
$('span.no').html(data);
}, function(){
$('#unCheck').click(function(){
$.post('insertCheckTour.php', ({checked: checked, depot: depot, date: date, tour: tour}), function(data){
$('.checkbox').animate({"opacity": "hide"}, {"duration": "slow"});
$('span.yes').html(data);
});
});
});
});
PHP code in other file:
- <?php
require_once("lib/lib.php");
$check = $_REQUEST['checked'];
$depot = $_REQUEST['depot'];
$date = $_REQUEST['date'];
$tour = $_REQUEST['tour'];
$img = $_REQUEST['img'];
$checked = new Check($check,$depot,$date,$tour,$img);
if($checked->insertCheckTour()== false){
echo "<span class=\"no\"><strong>No</strong></span>";
echo "<p id=\"check\">Check this runsheet: <input type=\"checkbox\" name=\"check\" id=\"check\" /></p>";
}else{
echo "<span class=\"yes\"><strong>Yes</strong></span>";
echo "<p id=\"unCheck\">Uncheck this runsheet: <input type=\"checkbox\" name=\"unCheck\" id=\"unCheck\" /></p>";
}
?>
Does anyone knows what I'm doing wrong here?
Thanks!