By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

if else syntax -

P: n/a
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;}
});
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* 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.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2

P: n/a
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.
Jun 27 '08 #3

P: n/a
daniel wrote:
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.
Which only leaves the silly mistake of using jQuery in its current form to
be corrected.

http://groups.google.com/groups?as_q...ing=d&filter=0
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.