Copy link to clipboard
Copied
I am trying to understand how Radio Buttons Work.
For example. How do I show an alert box when one of the radio Buttons are selected.
var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "Option A");
radio1.value = true;
var radio2 = w.add ("radiobutton", undefined, "Option B");
w.show();
Do you mean like this? Using onClick function?
var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "Option A");
radio1.value = true;
var radio2 = w.add ("radiobutton", undefined, "Option B");
radio2.onClick = function (){
alert ("hello world!")
}
w.show();
Copy link to clipboard
Copied
Do you mean like this? Using onClick function?
var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "Option A");
radio1.value = true;
var radio2 = w.add ("radiobutton", undefined, "Option B");
radio2.onClick = function (){
alert ("hello world!")
}
w.show();
Copy link to clipboard
Copied
Also, if you set the default value of radio1 to false, you can give that a function too.
You can still use onClick with radio1.value = true, but it means it will only occur when you click off and click back on.
var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "Option A");
radio1.value = false;
var radio2 = w.add ("radiobutton", undefined, "Option B");
radio2.onClick = function (){
alert ("hello world!")
}
radio1.onClick = function (){
alert ("bye world")
}
w.show();
Copy link to clipboard
Copied
Thank You. I never thought about the on click event, my mind was thinking on a change event for some reason.