Checkboxes and a button in the palette window

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
User avatar
BartlomiejOtlowski
Posts: 4
Joined: November 5th, 2015, 4:10 am
Location: Wroclaw, Poland
Contact:

Hi!
I want to make a window with 2 or more checkboxes and a button. Depends what is selected when I hit the button specific function will be executed. I don't know how to change values of the checkboxes in the opened script. It always has a value of runned script. No matter I select a checkbox or not. I tried something like this:

Code: Select all

var myWin = new Window("palette", "My Window", undefined);
    myWin.orientation = "row";

var groupOne = myWin.add("group", undefined, "GroupOne");
    groupOne.orientation = "column";
    var check1 = groupOne.add("checkbox", undefined, "CheckBox #1");
    var check2 = groupOne.add("checkbox", undefined, "CheckBox #2");
    var button1 = groupOne.add("button", undefined, "Button");

 if (button1.value == 1){
        var myFunction = function(){
            alert1();
        }
}else{
        var myFunction = function(){
            alert2();
    }
}

function alert1(){
alert("ONE_ONE_ONE");
}

function alert2(){
alert("TWO_TWO_TWO");
}

button1.onClick = myFunction


myWin.center();
myWin.show();
Thank you for your help!
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

The button1.onClick must collect the current checkboxes values:

Code: Select all

var myWin = new Window("palette", "My Window", undefined);
	myWin.orientation = "row";

var groupOne = myWin.add("group", undefined, "GroupOne");
	groupOne.orientation = "column";
	var check1 = groupOne.add("checkbox", undefined, "CheckBox #1");
	var check2 = groupOne.add("checkbox", undefined, "CheckBox #2");
	var button1 = groupOne.add("button", undefined, "Button");
	button1.onClick = function(){
		doStuff(check1.value, check2.value);
		};
function doStuff(option1, option2){
	var text = "";
	text += "option 1 enabled : " + option1;
	text += "\r";
	text += "option 2 enabled : " + option2;
	alert(text);
	};

myWin.center();
myWin.show();
User avatar
BartlomiejOtlowski
Posts: 4
Joined: November 5th, 2015, 4:10 am
Location: Wroclaw, Poland
Contact:

Thank you!
Post Reply