This topic is locked
[SOLVED]

Custom button to change field background colour

3/12/2022 5:15:52 PM
PHPRunner General questions
woodey2002 author

Hi Guys,

I have a custom botton on my edit page.

When the user clicks this button it should change the background colour of a field to green.

When the user clicks the same sutton for a second time it should change same fields background back to white.

I have some success adding this code to the buttons client before.

var ctrlB2 = Runner.getControl(pageid, 'patient_Name');
var value = ctrlB2.getValue();
if (ctrlB2.getValue()!=0){

ctrlB2.addStyle('background: green;');

}
return false;

It correctly changes the background to green.

But I can't figure out how the change the colour back to white if the users clicks the same button again.

In guess I need to figure how to to add a toggle like function to the button to accomodate multiple clicks.

Any ideas would be appreciated.

Thanks
J

Admin 3/14/2022

Not 100% sure I understand what the issue is. The following code should change the background back to white:

ctrlB2.addStyle('background: white;');

woodey2002 author 3/14/2022

Thank you.

The problem is that I can't get my custom button to recognise/fire a second condition after the second click.

So a user clicks the custom button once and the field turns green as expected however when the user clicks the same custom button again the field background should turn white.

click button1 once = background green
click button1 twice = background white

I can't figure out how to fire the background change after the user clicks the same button for the second time.

Cheers,
J

fhumanes 3/14/2022

Hello:

I think your problem is that you are not evaluating the value of the field when it changes value.

Look at this example that evaluates conditions when you interact with the field. There you should introduce the function of evaluating the content and changing to one color or other the bottom of the field.

https://xlinesoft.com/phprunner/docs/ctrl_setvalue.htm

Greetings,
fernando

Admin 3/14/2022

This code doesn't know if it runs the first time or the second time so you need something else to figure out that. When this button is clicked, change the value of any fields? Or just change the background? You are supposed to change the alue of one of fields i.e. from 0 to 1 and vice versa. Then you can based your logic on this field value and set the background accordingly.

woodey2002 author 3/14/2022

Thanks very much to you both.

That makes sense now.

Cheers,
J