Reputation: 5150
$('#myClick2').click(function () {
var value = $(this).val();
If (value != 'on') {
$.getJSON('message_center_getMessageLists.asp', {}, function (json) {
alert(json.one);
alert(json.two);
alert(json.three);
})
.error(function () { alert("There was an error while trying to make this request; If it persists please contact support"); });
}
});
The $.getJSON part was working just fine until I wrapped the IF statement around it. I am trying to get the check box to execute the .getJSON only if it is not currently checked. Anyone have any idea what I am doing incorrectly?
Upvotes: 0
Views: 52
Reputation: 16297
You if
statement is capitalized. Change it to lowercase and that should fix your problem.
Also are you sure that the value
is in fact not equal to on
?
UPDATE
Then what you want to do is use this.checked
in the if statement.
Upvotes: 2
Reputation:
"...execute the .getJSON only if it is not currently checked"
Then do it like this...
if (!this.checked) {
$.getJSON(...
Upvotes: 4
Reputation: 887315
.val()
returns the value of the value
attribute.
You want if (this.checked)
(no jQuery) or if ($(this).is(':checked'))
Upvotes: 1