This topic is locked
[SOLVED]

 Calculating on the fly from a button click

10/9/2013 10:17:08 AM
PHPRunner General questions
D
ductsoup author

The manual page below makes perfect sense to me and works fine but it doesn't quite do what I'd like.
"How to calculate values on the fly"

My link
I want to add a button to an add or edit page then when the user clicks, copy either a constant, or a value from another field on the page to the field next to the button. I don't want to commit the change until the user hits save.
In the OnLoad event I'm not sure how to reference the button object to attach the action. In the ClientBefore, I'm not sure how access the field objects.
I'm sure I'm missing something obvious. Can anyone fill me in?
Thanks

C
cgphp 10/9/2013

In the "Client before" event of the button, enter the following code:

var source = Runner.getControl(pageid, 'my_field_name_1');

var target = Runner.getControl(pageid, 'my_field_name_2');

target.setValue(source.getValue());

return false;


Replace my_field_name_1 and my_field_name_2 with the real names of your fields.

D
ductsoup author 10/10/2013



In the "Client before" event of the button, enter the following code:

var source = Runner.getControl(pageid, 'my_field_name_1');

var target = Runner.getControl(pageid, 'my_field_name_2');

target.setValue(source.getValue());

return false;


Replace my_field_name_1 and my_field_name_2 with the real names of your fields.


Thanks, but that's exactly where I hit the wall.
As pageid isn't passed to "Client before" like it is in "JavaScript OnLoad event" I'm thinking it is out of context so the getControl method is returning nothing.

function OnClient Before(params,ctrl)

function OnPageLoad(pageObj,pageid,proxy,inlineRow)



Is there another way to reference pageid or the field controls from within "Client before"?
I should've mentioned this is PHPRunner 7.0.

C
cgphp 10/10/2013

PHPrunner 7.0 is a beta version. In PHPrunner 6.2 my code works fine.

D
ductsoup author 10/10/2013



PHPrunner 7.0 is a beta version. In PHPrunner 6.2 my code works fine.


Tried it again, you are correct. Must've missed something the first time through.
Thanks for your help.