this code works fine without the if condition test, where am I going wrong here with the if condition?
$(document).ready(function() {
if ($("input[name=contest_open]").val() == true) {
var refreshId = setInterval(function()
{
$('#tweets').fadeOut("slow").fadeIn("slow");
$.get("/event", { event:$("input[name=event]").val(), }, function(data) {
console.log(data.success);
console.log(data.page_link);
console.log('Succesfully Loaded Data from JSON FORMAT GET');
$('#tweets').html(data.html);
$('#pagelink').html(data.page_link);
});
}, 30000);
}
})
The problem is that
valdoes not return a boolean value. If you are trying to check whether thevalueofinput[name=contest_open]is not empty, tryval() !== ""instead.If you are trying to check whether the value is the string “true”, you need to enclose
truewith quotes.