• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

323

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

Community Expert , 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:

...

Votes

Translate

Translate
Adobe
Community Expert ,
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");

}

Votes

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

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

basic error 😞

Votes

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
Community Expert ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

LATEST

sometimes those are the hardest ones to find.

Votes

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