User 515127 Photo

Registered User
112 posts

Scenario - I want to use a checkbox to update a Boolean database 'flag' re: status of an inventory item - active or inactive.

Form pulls a list of the inventory items into a dropdown via XML using the body onload event. (Thank you Frank Cook for enlightening me to the fact that attaching an attribute to the grid would place it into the body tag) FWIW - an easy way to bring up the grid within the right-hand column design tab- is to snag any context tag and scroll down to the bottom of the displayed list, there it is.

Problem: Checkboxes tend to be a PITA anyway... and RSD does this Solomon act while implementing a checkbox element. While the 'type' says checkbox in the design details - it's semi-lying by omission of a key detail. RSD is actually creating a label element to encapsulate an input type=checkbox element and putting the assigned text within a span element as another child within the label. The particularly misleading aspect that cost me a couple hours of muttering and hair-pulling - is that, while in their let's cut the baby in half Solomon mode, the CC developers decided to assign the ID attribute you insert to the so-called checkbox element to the label and the name attribute to the checkbox (<label class=blahblah id=name> <input type=checkbox name=??? ... ><span> my checkbox </span></label>)

If you are simply posting the state of the checkbox - okay, that is usually done via the name attribute so no harm, no foul as in $myVar = $_POST['MyName'];

However, if you are looking up and seek to display the Boolean 'status' of something, like an inventory item for instance, active or inactive - or perhaps in stock or not in stock or below min inventory qty on hand, You are typically going to show or modify that attribute that using the ID. document.getElementById("myID").checked = true or false. Now ... as I discovered after chasing a few blind alleys - the label element doesn't make much use of the checked attribute.

The work around is to either 'fix' the id assignment - then you have another 'remember to do that edit manually, after every time you edit and export the page, or go another way.

I chose to chase the name attribute using the alternate means however that requires a bit more typing and knowing whether you have more than one element with the same name, because the call by Name returns an array so you have to inform javascript about the ordinal value of the element you wish to play with.

var cb = document.getElementsByName("name");
if (myStatus == 1) then
{ cb[0].checked = true;
cb[0].value = 1;
} else {
cb[0].checked = false;
cb[0].value = 0;

This seems to be working... <sigh> I wish I had the couple three hours back that I spent trying to figure out what was wrong with my javascript because I "KNEW" that I had assigned the ID status to my checkbox so obviously, I had some other coding error.

User 187934 Photo

Senior Advisor
18,330 posts
Online Now

I've gotten in the habit of targeting inputs by name now as it's easier to read the js and actual tell what your targeting after not looking at it for a while. I use a similar method with Form Builder checkboxes. Arrays are awesome.:lol:
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
Here's my CoffeeCup SCCP Shop with examples of what can be done.
This is a site I built for my work.(RSD)
This is a site I built for use in my job.(HTML Editor)
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.