Hi
I only want users to be able to tick a checkbox if other areas of the system are complete. I can check whether the other areas have been completed when the checkbox is ticked and pass a message back if the other areas haven't been completed but the checkbox stays selected. How do I make the checkbox unselected if the check fails?
Here's what I have
I only want users to be able to tick a checkbox if other areas of the system are complete. I can check whether the other areas have been completed when the checkbox is ticked and pass a message back if the other areas haven't been completed but the checkbox stays selected. How do I make the checkbox unselected if the check fails?
Here's what I have
Code:
<script type="text/javascript">
function checkCompleted() {
$.ajax( {
type: 'POST',
url: 'checkCompleted.php',
data: { checked_box : $('input:checkbox:checked').val()},
success: function(data) {
$('#response').html(data);
}
} );
}
</script>
<input type="checkbox" name="checked_box" value="1" onclick="checkCompleted()">
<div class='#response'></div>
checkCompleted.php:
<?php
include "config.php";
if (isset($_POST['checked_box'])) {
//connect to database and test for completion of other fields
if (!$dataCompleted) {
echo 'You have not completed the other areas, please complete the other areas before ticking this box.';
}
}
?>