How can I get a checkbox checked state in an event handler?
I am working on a script to add a frame to my photographs. The UI can be seen here. The checkbox to use hexadecimal values for colors is checked, but when I click the "White" button, decimal numbers are used.
Here is the code initializing the check box:
this.TextColorHex = this.TextColorGroup.add("checkbox", undefined, undefined, {name: "TextColorHex"});
this.TextColorHex.text = "Hex";
this.TextColorHex.checked = false;
alert ("TextColorHex status initialized to " + this.TextColorHex.checked);
I have the dialog box containing this checkbox wrapped into a class, hence the use of "this". I had to explicitly initialize the checked property to "false" because the alert was telling me it was undefined, which surprised me. I expected it to be false by default.
The White button is initialized like this:
this.WhiteButton = this.group2.add("button", undefined, undefined, {name: "WhiteButton"});
this.WhiteButton.text = "White";
this.WhiteButton.tag = this;
this.WhiteButton.addEventListener("click", this.OnWhiteClick)
Putting the dialog object into the button's tag property makes it available in the event handler, which looks like this:
FrameDialog.prototype.OnWhiteClick = function(e)
{
alert ("Hex checkbox status: " + e.target.tag.TextColorHex.checked);
if (e.target.tag.TextColorHex.checked)
{
e.target.tag.TextColorR.text = "ff";
e.target.tag.TextColorG.text = "ff";
e.target.tag.TextColorB.text = "ff";
}
else
{
e.target.tag.TextColorR.text = "255";
e.target.tag.TextColorG.text = "255";
e.target.tag.TextColorB.text = "255";
}
}
But when I click the checkbox to use hex and then click the White button, the alert tells me that the checkbox's check state is False! Why isn't this reporting the true state of the checkbox?
And I found another oddity: when I initialized the checkbox to true, the checkbox did not show a check mark, but the alert just after creating the checkbox reports that the checked state is true!
What is going on with the checkbox? How can I reliably use its state?
