Validate RadioButton

Participant ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

Hey Guys,

I need to validate RadioButtons, my script below doesn´t works
Could you please guys give a hand
Im not sure What Im doing wrong

Any help will be appreciate !

 

*--------------------------------------

var w = new Window ("dialog","Testing 1");
var radio_group = w.add ("panel");
radio_group.alignChildren = "left";

// add Radiobuttons
var radio1 = radio_group.add ("radiobutton", undefined, "UNO");
var radio2 = radio_group.add ("radiobutton", undefined, "DOS");
radio1.value = true;
var radio3 = radio_group.add ("radiobutton", undefined, "TRES");

//adding button
var b1 = w.add ("button", undefined, "Ok");
b1.onClick = Anidados;

//validating radiobuttons
function Anidados(){
if(radio1.value=true){
alert("Hola soy Uno");

} else if (radio2.value=true){
alert("Hola soy Dos");

} else if(radio3.value=true){
alert("Hola soy Tres");
}
}
w.show ();

TOPICS
Scripting

Views

151

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 09, 2021 Mar 09, 2021
you've made a classic programming faux pas. we've all done it many times. In your conditional statements, you're not checking for equality, you're assigning the value of "radio1.value" to "true" which causes no error, and thus the condition returns true and you get that alert message. In other words, no matter what radio button you select, when you click "OK", the script makes radio1.active "true" which is why you always get the same alert message. Change your conditionals to this instead:...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

you've made a classic programming faux pas. we've all done it many times.

 

In your conditional statements, you're not checking for equality, you're assigning the value of "radio1.value" to "true" which causes no error, and thus the condition returns true and you get that alert message.

 

In other words, no matter what radio button you select, when you click "OK", the script makes radio1.active "true" which is why you always get the same alert message.

 

Change your conditionals to this instead:

if(radio1.value === true)

{

    alert("Hola soy Uno");

}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

@DilliamWowling  Oh Man!  Thank you so much! its works good now!  🙂

basic error 😞

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

LATEST

sometimes those are the hardest ones to find.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines