I have been looking at a lot of examples on how to accomplish this but cannot get it to work. I just want to put a simple if statement within my javascript, and when I add the if, it breaks? I am getting test to report true when checked, and false when unchecked, so what am I missing? - Novice user, so if this a convoluted way to do this, I apologize.
NOT WORKING:
<script>
$('input[name="1"]').click(function() {
var test = $(this).prop('checked'); //{
if(test == "true")
{
var alert_id = $(this).val();
var key = $('#key').val();
$.ajax({
type: "POST",
url: "functions/database_write.php",
data: "id1="+alert_id+"&key="+key+"&test="+test,
success: function(resp){
$( ".pop-div" ).slideDown(100,"linear");
setTimeout(function(){
$( ".pop-div" ).slideUp(100,"linear");
}, 1000);
//alert(resp);
},
error: function(e){
alert('Error: ' + e);
}
}
})
});
</script>
But works, but with every click when the function is written like:
<script>
$('input[name="1"]').click(function() {
var test = $(this).prop('checked'); //{
//if(test == "true")
//{
var alert_id = $(this).val();
var key = $('#key').val();
$.ajax({
type: "POST",
url: "functions/database_write.php",
data: "id1="+alert_id+"&key="+key+"&test="+test,
success: function(resp){
$( ".pop-div" ).slideDown(100,"linear");
setTimeout(function(){
$( ".pop-div" ).slideUp(100,"linear");
}, 1000);
//alert(resp);
},
error: function(e){
alert('Error: ' + e);
}
//}
})
});
</script>