last day (15 days later) » 

9:23 PM
0
Q: if statement not checking values as expected

Ariel ZabihiI have an if statement checking if the value of a php check box is checked. For some reason it only stops at the if statement and wont run the else. If I switch the rules of the if statement with the [initial] else statement I still only get the if statement. $(document).ready(function(){ ...

 
Do us a favor and console.log/console.dir your data variable. It's likely not what you think it is.
 
What is the inview event? Are you using this plugin: github.com/protonet/jquery.inview
 
@zfrisch That was my initial problem. Google Chrome console log isn't showing anything at all:
 
Where do you check if a checkbox is checked? The checkboxes are shape, color, enhancement, and matching, but you never test any of them in if` statements.
What does get_filter() do?
 
@Barmar it is: jquery.inview.js, I think I got it from the same github page too
@ I tried if( data+':not(:checked) {' but had the same problem
@Barmar function get_filter(class_name) { var filter = []; $('.'+class_name+':checked').each(function(){ filter.push($(this).val()); }); return filter; }
 
9:23 PM
What is data supposed to be? How is it related to the checkboxes?
 
@Barmar the values in data are the class names of the checkboxes
 
Class names? Is it a JSON array?
 
@Barmar it uses` jQuery( selector [, context ] )` jQuery context with selector from function get_filter(class_name)
 
data is the response from the PHP script, it has nothing to do with get_filter().
 
@Barmar so I should put the if statement under the get_filter() function?
 
9:23 PM
I guess so. It should be something like if (shape.length > 0 && color.length > 0 ...)
 
@Barmar //Checking applied filters function get_filter(class_name) { var filter = []; $('.'+class_name+':checked').each(function(){ filter.push($(this).val()); }); if(shape.length && color.length && enhancement.length && matching.length == 0) { $('.LoaderContainer').hide(); //Hide infinite scroll } else { $('.LoaderContainer').show(); //Show infinite scroll } return filter; } Doesn't seem to do anything
 
The $.ajax() call should be in the if block.
 
@Barmar How do you check the length of a checkbox as a string?
 
You don't. get_filter() returns an array, that's why you check the length of the array. It will be empty if none of the boxes are checked.
 
@Barmar Would wrapping both the inView and get_filter() functions around your if statement work?
 
9:23 PM
That makes no sense. The if statement is checking the values returned by get_filter(). How can you put the if before calling get_filter()?
You need to update the question to explain what you're trying to accomplish with the if statement.
 
@Barmar I realized that didn't make sense till after I wrote it. Sorry. Are you saying I should update my question on Stack Overflow or the if statement in my code? lol
 

last day (15 days later) »