How to set a condition with a radio button?

How to set a condition with a radio button? I have tried these two ways but it doesn't work.

if (btn_radio1 == "click") {
if (btn_radio1 = true) {

Control.value gets you the value of a control, for a checkbox that'll be either true/false or 0/1/2.

E.g. if (dlg.Control('btn_radio1').value) { ... }

1 Like

Thank you a thousand times @Jon!!!

I have two radio buttons, and I would like that when I select one of them, the values of the "ancho" and "alto" controls change, but I select the buttons and the values of the controls do not change? What am I doing wrong?

	if (dlg.Control("btn_pixeles").value = true) {
	    dlg.Control("ancho").value = item.metadata.image.picwidth;
	    dlg.Control("alto").value = item.metadata.image.picheight;
	}

	if (dlg.Control("btn_por_ciento").value = true) {
	    dlg.Control("ancho").value = 100;
	    dlg.Control("alto").value = 100;
	}

You need to use == to test for equality.

Thanks @Jon, but I had already tried this way but the values do not change either.

So
if (dlg.Control("btn_pixeles").value == true) {
does not work either`?

For debugging, I would do some kind of logging in this case instead of modifying the values. Maybe the control names you used are not correct or the way to change them is wrong?

if (dlg.Control("btn_pixeles").value == true) {
//logging
//logging
}

Hello @Micky, thanks for your interaction, if (dlg.Control("btn_pixeles").value == true) { does work, the problem was that I was putting the conditions before dlg.Show. I still don't understand why some controls have to go before and others after dlg.Show.

You should test if (dlg.Control("btn_pixeles").value) without the == true part.

(This is not specific to any of the Opus stuff. It's true for boolean tests in JavaScript in general, as well as many other languages. Comparing against true will work sometimes but will also cause problems at other times that might be hard to work out. It's good to avoid the habit.)

1 Like

Thank you very much @Leo, I'm going to make the corrections, maybe that's why the code is half crazy :smile: