Topic: API to change checkbox

I am using the YES|NO style check box input.
it seems like doing : element.checked = true; doesn't effect it.
I believe its a missing feature.

I need it because I want to save the checkbox state in a cookie and restore it on-load.


Re: API to change checkbox

Hum in fact, was working before... I'll check it smile

Re: API to change checkbox

I have exactly the same issue.

WA is establishing the initial "look" of the checkbox (i.e., is it checked or unchecked) at document load time based on the value of the "checked" attribute on the checkbox element as it appears in the HTML. Once that's been done, checkboxes only change their appearance (change from one state to the other) when they are clicked on, which results in the FlipCheck() function being called as an event handler for the click.

This is all fine, provided that you can code the starting state of your checkboxes in the HTML.

The problem occurs when you want to determine the starting state at run time - for example, by loading the last-set values from cookies. Setting the "checked" attribute on the checkbox element via JavaScript and the DOM doesn't do any good, because WA has already created the checkbox using whatever value the attribute had in the HTML. Now, the only way to change the checkbox is to call FlipCheck(), but that's a private function, and there's no way to call it from our JavaScript.

I'm not sure what the right fix is here; the code in InitCheck() and FlipCheck() is a little obscure without more study than I've put into it so far.

Chrilith, any ideas?

Re: API to change checkbox

With current there is no way to do this. I'll add a function to refresh the state.

Re: API to change checkbox

The following seems to do the job.

It might have been cleaner to put the code from FlipCheck(), which is repeated here, into a separate function that both FlipCheck() and SetCheckbox() could call, but I chose to implement this without modifying the WebApp code (other than pasting this in around line 245).

SetCheckbox: function(cb, state) {
    // cb = the original checkbox
    // cb.previousSibling = InitCheck()->b1
    // cb.previousSibling.childNodes[0] = #text (" ")
    // cb.previousSibling.childNodes[1] = InitCheck()->b2
    // cb.previousSibling.childNodes[2] = InitCheck()->i1
    var b2 = cb.previousSibling.childNodes[1];
    var txt = cb.title.split("|");

    cb.checked = (state == "true" ? true : false);

    with (b2.nextSibling) {
        innerHTML = txt[cb.checked ? 0 : 1];
        if (cb.checked) {
   = "";
   = "-1px";
            b2.parentNode.className = "iToggleOn";
            style.left = 0;
            style.right = "";
        else {
   = "-1px";
   = "";
            b2.parentNode.className = "iToggle";
            style.left = "";
            style.right = 0;

General usage:

    <form name="myFormName" ...>
        <input type="checkbox" name="myCheckBoxName" ... />

    WA.SetCheckbox(document.forms.myFormName.elements.myCheckBoxName, true|false);

The second parameter can be either a boolean (as shown) or a string (e.g., "true"). Personally I think it's easier to do it with strings, generally.

Last edited by tnstatc (2008-11-19 18:05:03)

Re: API to change checkbox

Nice, not really the way I'll do it, but it's a good one.

Re: API to change checkbox

Ok, this bug/feature has been fixed/added in the private beta and will be available with next release

Re: API to change checkbox

Can you check RC4U2 and let me know if it is fixed for you?

Re: API to change checkbox

Re: API to change checkbox