Boolean Toggle

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.

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

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();

Ahh – thanks. I did the same thing with lasso when I was learning it so I should have figured this one out…

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