Page 1 of 1

Boolean Toggle

PostPosted: Wed Apr 30, 2003 8:44 pm
by david
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.

Boolean Toggle

PostPosted: Wed Apr 30, 2003 9:52 pm
by automazione
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

PostPosted: Wed Apr 30, 2003 9:52 pm
by Guest
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();

PostPosted: Wed Apr 30, 2003 10:00 pm
by david
Ahh -- thanks. I did the same thing with lasso when I was learning it so I should have figured this one out....

PostPosted: Wed Apr 30, 2003 10:04 pm
by Jan Aleman
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