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 ();
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:
...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");
}
Copy link to clipboard
Copied
@Disposition_Dev Oh Man! Thank you so much! its works good now! 🙂
basic error 😞
Copy link to clipboard
Copied
sometimes those are the hardest ones to find.