It's really unclear what you are trying to do, but I may be able to help anyway.
Here's what you have, more or less: http://jsfiddle.net/ySqGg/
I should get red text1 But I am getting red text1 + text 'true'
This happens because you are "adding" true
to a string.
variablefotok = variablefot=true;
// variablefotok and variablefofot are now both set to true
variable1 = 'text1' +variablefotok;
// same as: variable1 = 'text1' + true;
// `true` is converted into a string so it can be combined with a string
// variable1 is now `text1true`
So why does that happen? Well lets look one line earlier:
variablefot = false;
variablefotok = variablefot = true;
This can be clarified as follows:
variablefot = false;
variablefotok = (variablefot = true);
So first you set variablefot
to false
. Then on the next line you set it to true
. Assignment statements return the assigned value, and so you set variablefotok
to true as well.
Then later f2
runs, and variablefot
is now true, and you get red.
Did you mean to do a comparison instead?
variablefotok = (variablefot == true);
With this change, the text does not turn red, because variablefot
remains false
. http://jsfiddle.net/ySqGg/1/
But you rarely have to compare anything to true
. You can simply use the variable, since it's true
or false
.
variablefotok = variablefot;
Which also does not turn anything red. See: http://jsfiddle.net/ySqGg/2/
This is confusing to answer because you are setting many variables, but only using one for anything usefult (variablefot
in f2
). If I were you I'd think about what variables you have and make sure you really need every one, then delete the others.