This topic is locked
[SOLVED]

OnChange giving old boolean values

12/25/2024 11:06:52 AM
PHPRunner General questions
A
Abu author

I have a boolean field with "YES" or "NO" values.

Using event I will like to show different fields according to values chosen.

So in the client before for OnChange event I have put the following codes.


if (this.getValue() == "YES"){

pageObj.toggleItem("integrated_edit_field5", true);

} else {

pageObj.toggleItem("integrated_edit_field5", false );

}
return false;


Unfortunately, the response I was getting was the reverse to what I was expecting. To explain further;
I added in, an alert command.

if (this.getValue() == "YES"){
alert("YES");
pageObj.toggleItem("integrated_edit_field5", true);

} else {
alert("NO");
pageObj.toggleItem("integrated_edit_field5", false );

}
return false;


When it was suppose to be true, I get a NO alert, and when It was suppose to be NO, I get a YES alert instead.

It is as if, javascript is giving me the previous value rather than the latest clicked value.

I could still make things to work, by arranging things in reverse. But that should not be the case.

M
MikeUk 12/25/2024

Use console.log('Value: ' + this.getValue());

That will show you what value is set for each option. Then you can fix your code.
If it's a checkbox, it should show 'on' for checked and '' for unchecked.

Mike

A
Abu author 12/25/2024

Use console.log('Value: ' + this.getValue());

Thanks for the suggestion.

It confirms what I have observed.
Using radiobutton with or without horizontal layout, it returns the oposite value. YES when click NO, and NO when click YES.

BTW
The log returned correctly when using checkbox. YES or NO as selected.
But I only wanted to select one.
The log also returned correctly when using dropdown box. So this seems like the solution for me.
Nevertheless, I still like the radio button.

I wonder if this is a bug with the radio button. Using PHPRunner Enterprise 10.91 (Build 40885 x64)

A
Abu author 12/25/2024

Update:
My error. Apparently in the many attempt of trial and error, I have left the event handler as on'click' rather than on'change'.

The radio button worked correctly when reverted to on'change'