Text String from checkbox
Hey yall,
I'm attempting to create an interface that can create a text string from the selections made in a list. It seems rudimentary, but it has me completely stumped. Below you will find what I've pieced together so far, but I'm struggling to string these options together. I'm trying to get the string format to be "Chips and Hot Dog" if those are the two options selected on the list. Any help is appreciated and you may recognize some of your code below!
function container() {
var foodTypes = ["Apples","Oranges","Chips","Hot Dogs","Hamburgers","Ice Cream","Pie"]
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Food Type Selector";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
// OPTIONSPANEL
// ============
var optionsPanel = dialog.add("panel", undefined, undefined, {name: "optionsPanel"});
optionsPanel.text = "Food Types";
optionsPanel.orientation = "column";
optionsPanel.alignChildren = ["left","top"];
optionsPanel.spacing = 10;
optionsPanel.margins = 14;
optionsPanel.multiselect = true;
var cbg = optionsPanel.add("group");
cbg.orientation = "column";
cbg.alignChildren = ["left","top"];
var patternTypesChecks = [];
for (var i = 0; i < foodTypes.length; i++) {
checkBox = cbg.add("checkbox", undefined, foodTypes[i]);
}
// DIALOG
// ======
var button1 = dialog.add("button", undefined, undefined, {name: "button1"});
button1.text = "Okay";
button1.preferredSize.width = 125;
button1.onClick = function(){
var msg = '\r';
for (var j=0; j<cbg.children.length; j++){
if(cbg.children.value == true){
msg += cbg.children.text + '\r';}
dialog.close();
}; };
dialog.show();
}
container()
alert(msg);
