if else syntax -

D

daniel

I'm trying to do a simply if else thing but for some reason it doesn't
work. The commented code works - as you can see I'm using jquery but
the problem only happens when I convert the two .click functions into
one with an if.. else statement. The commented section works but i
would like to get the simpler one following working.

/* $("#unsubscribe").hide();

$("#subscribe h4 a").click(function(){
$("#subscribe").hide();
$("#unsubscribe").fadeIn();
return false;
});
$("#unsubscribe h4 a").click(function(){
$("#unsubscribe").hide();
$("#subscribe").fadeIn();
return false;
});*/


$("#unsubscribe").hide();
var formswitch = 0;

$(".left h4 a").click(function(){
if (formswitch == 0) {$("#subscribe").hide();
$("#unsubscribe").fadeIn();
var formswitch = 1;
return false;}
else {$("#unsubscribe").hide();
$("#subscribe").fadeIn();
return false;}
});
 
B

Bjoern Hoehrmann

* daniel wrote in comp.lang.javascript:
I'm trying to do a simply if else thing but for some reason it doesn't
work. The commented code works - as you can see I'm using jquery but
the problem only happens when I convert the two .click functions into
one with an if.. else statement. The commented section works but i
would like to get the simpler one following working.
var formswitch = 0;

$(".left h4 a").click(function(){
if (formswitch == 0) {$("#subscribe").hide();
$("#unsubscribe").fadeIn();
var formswitch = 1;

Presumably you did not mean to specify the 'var' here; other than that
there seems little wrong with this, though I would strongly suggest to
use proper indentation at least when asking others to debug your code,
and you might want to put the "return false" at the end of the function
rather than duplicate it.
 
D

daniel

I'm not sure which one it was but that was the fix. I think the silly
mistake of putting the var in there was it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top