Boolean Toggle

Questions, tips and tricks and techniques for scripting in Servoy

Boolean Toggle

Postby david » Wed Apr 30, 2003 8:44 pm

I'm just starting to figure out JavaScript so a general basic question warning applies to my posts for the next several months :)

This code will change "yes" to "no" but won't change "no" to "yes":

if(web_visible='Yes')
{
web_visible='No';
}
else
{
web_visible='Yes';
}
controller.saveData();

I'm trying to get a button to toggle between "yes" and "no" when activated.
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Boolean Toggle

Postby automazione » Wed Apr 30, 2003 9:52 pm

if(web_visible=='Yes')

will work.

---------------------------

x == y x and y are equal
x != y x and y are not equal
x > y x is greater than y
x >= y x is greater or equal to y
x < y x is less than y
x <= y x is less than or equal to

-------------------

ciao

Enrico
automazione
 
Posts: 366
Joined: Thu Apr 24, 2003 11:37 am
Location: Torino, Italy

Postby Guest » Wed Apr 30, 2003 9:52 pm

A single = is an assignment operator. So in your case you are assigning Yes to web_visible which returns true (because the assignment went correctly) which cause it to set it back to No.

To test for a value use ==

if(web_visible=='Yes')
{
web_visible='No';
}
else
{
web_visible='Yes';
}
controller.saveData();
Guest
 

Postby david » Wed Apr 30, 2003 10:00 pm

Ahh -- thanks. I did the same thing with lasso when I was learning it so I should have figured this one out....
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Postby Jan Aleman » Wed Apr 30, 2003 10:04 pm

I still do it regularly :)
I tend to turn on the debugger when i can't figure it out. It really helps to see what sits inside your variables and into which if's are branched
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth


Return to Methods

Who is online

Users browsing this forum: No registered users and 9 guests

cron