jQuery IF statement for displaying/hiding a facebox

60 views Asked by At

Not sure I did this correctly, but here is my stab at JSfiddle: http://jsfiddle.net/EQ4mA/2/

Let me preface this with admitting that I have little to no experience with jQuery (I am proficient with html/css), but my team has lost our development allotted hours, and I have been tasked with the following:

Create a 5 page flow Create a facebox on page 3 of that flow Style the facebox so that if a user is navigating FROM page 2 TO page 3, the facebox will display. IF the user is navigating FROM page 4 TO page 3, the facebox must be hidden. That is to say, the user clicks the back button on page 4, the facebox should not appear on page 3.

The good news: I have created a (functioning, yay!) facebox on page 3, however, I am at a loss where to go next. My flow works and functions great, but I have no clue how to have the facebox only display from page 2 to 3, and not from 4 to 3.

I have:

jQuery(document).ready(
function() {
if("${user.last_mbox_before_choice_page}" != 'Act 3 Sidebar Profile') {
jQuery('#premier_interstitial_main').hide();
jQuery('.pagebody_div').show();
} 

I'm guessing I'm missing a var = statement, but I'm not sure how those work. Any help is greatly appreciated!!

1

There are 1 answers

1
DarthCaniac On

Change:

if("${user.last_mbox_before_choice_page}" != 'Act 3 Sidebar Profile') {
jQuery('#premier_interstitial_main').hide();
jQuery('.pagebody_div').show();
} 

to:

if(${user.last_mbox_before_choice_page} !== "Act 3 Sidebar Profile") {
jQuery('#premier_interstitial_main').hide();
jQuery('.pagebody_div').show();
} 

You shouldn't put quotes around variables, because then it will treat them as a string, and obviously, the two strings don't match :) Also, the operator ("!=") was not correct. You want to use "!==", which means different type or different value. You can read more about operators here: http://www.w3schools.com/js/js_comparisons.asp