- Joined
- Oct 29, 2012
- Messages
- 94
I have the following code that changes something in the database via AJAX. When the input checkbox is checked, the database variable updates, and the message "Your Profile Has Been Updated!" appears to the end-user. It currently is embedded in a PHP file, hence all the backslashes.
In php_file.php:
What I would like to happen is to get two different messages: one for when the checkbox is checked by the end-user, and a different one for when the checkbox is unchecked. For example, when it is checked, it says:
* Your Profile Has Been Updated!
* Your Profile Hasn't Been Updated!
In other words, the checkbox act as a toggle switch with a different message depending on its activation status.
Any suggestions?
Code:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: \'POST\',
url: \'\php_file.php\',
data: { hide_info : $(\'input:checkbox:checked\').val()},
success: function(data) {
$(\'#message\').html(\'<div>Your Profile Has Been Updated!</div>\');
}
} );
}
</script>
<input type="checkbox" name="hide_info" value="1" onclick="processForm()">
<span id="message"></span>
In php_file.php:
Code:
$checkbox = intval($_POST['hide_info']);
if($checkbox == 1){
$check_status = 1;
}else{
$check_status = 0;
}
mysql_query("UPDATE users SET hide_info = $check_status WHERE userID = 1");
What I would like to happen is to get two different messages: one for when the checkbox is checked by the end-user, and a different one for when the checkbox is unchecked. For example, when it is checked, it says:
* Your Profile Has Been Updated!
* Your Profile Hasn't Been Updated!
In other words, the checkbox act as a toggle switch with a different message depending on its activation status.
Any suggestions?