473,413 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

if else syntax -

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
3 1245
* 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: phaser2001 | last post by:
Hi all, I have the below user-defined function on mssql 2000 and I can't work out why i'm getting the following error: ----- Server: Msg 156, Level 15, State 1, Procedure...
5
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on this...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) {...
0
by: stef mientki | last post by:
hello, I've the idea that the "else" syntax is not always handled correctly, or I'm overlooking something. This pieces of code are automatic translation from another language, sometimes it...
8
by: callumagus | last post by:
Python Version 2.0 Windows Vista (I know, I know...) Im very new to python and have only been doing it for two weeks. print 'Type in lowercase!'; String_Var = raw_input ('Add, Divide,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.