Checking a checkbox with script

11 views
Skip to first unread message

mapicurious.com

unread,
Mar 19, 2008, 2:26:35 PM3/19/08
to WHERE GPS Developers
function doSetChecked5() {

//Find out how many entries are in string by dividing by 3
var prevList = load('customprefs');

var listLen = prevList.length();
var listItems = listLen / 3;
var posList = 1;
var list = document.sliceprefs;

for (var k = 0; k <= listItems; k++) {

var m = prevList.substring(k*3,(k*3) +2);

var choice = document.getNodeById(m);
//alert('Choice is ' + m);

//choice.checked = true;
//choice.isChecked = true;
choice.isSelected = true;
}
}

.....In the body:

<choice type="check" id="sliceprefs">
<input type="choice" id="01" bgfocus="0xFFFF00" checked="false">Choice
A</input>
<input type="choice" id="02" bgfocus="0xFFFF00" checked="false">Choice
B</input>
</choice>


My question is, based on the script above, which choice will actually
check the checkbox choice:

A) choice.checked = true;

B) choice.isChecked = true;

C) choice.isSelected = true;


The pattern here is to store a list of choice ids seperated by a
comma:

customprefs = 01,02,

With this set on the handset, a button with the above script would
check Choice A and Choice B.

Thanks,

Brad

Gil Cunningham

unread,
Mar 19, 2008, 2:37:40 PM3/19/08
to WHERE GPS Developers
Brad-
Its not particularly well documented, but the <choice> element is a
list object.
Here are the docs for the dealing with a list object in the script ...

http://where.com/create/reference/variables.php#list

I believe that you are just trying to "check" the desired checkbox,
correct ?

So, you will want to interact with the choice element
(id="sliceprefs") like so ...

// logic above to determine var "index"
document.getNodeById('sliceprefs').setSelected(index);

mapicurious.com

unread,
Mar 19, 2008, 4:30:25 PM3/19/08
to WHERE GPS Developers
Thanks for the help.

Altered the code to get the full functionality:

var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

for (var k = 0; k <= listItems; k++) {
var m = prevList.substring(k*2,(k*2) +1);
document.getNodeById('sliceprefs').setSelected(alpha.indexOf(m));
}
}

This will allow you to save a single character comma delimited list of
settings to a single preference, and recheck them in the list.

Thanks,

Brad
> > Brad- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages