This topic is locked

Setting a calculated default value?

6/11/2012 11:27:04 AM
PHPRunner General questions
S
sradforth author

I'm trying to set a default value in a datetime edit box that is calculated on the server and sent to the client.

I.e. On the server I calculate the first time slot that is available for a resource which seems to work and I've got the string '11/3/2013 09:00' being returned for example. All I want to do is have this appear as the default time in the starttime edit box I have in my item's 'Add' page.
I've tried adding a code snippet into the Add page that calculates the value and store the result in $_SESSION['startTime']; which I next tried setting as the default value for the starttime control. Unfortunately this seems to be a page behind so the last calculation is used, not the current one which seems to indicate the page is built first then the custom php scripts are run.

I next thought what I should do is send this default value over to the client and use java script to set it. Before I did that I tried setting the timedate parameter in the Java OnLoad method of the Add page like this.



var ctrlTimeStart = Runner.getControl(pageid, 'time_start');

ctrlTimeStart.setValue('01/01/2014 09:00');


Unfortunately this doesn't appear to do anything and the text value is blank. I'm a newbie to PHP/JavaScript so probably making some very basic mistakes here but any pointers would be much appreciated as really not sure how best to set a control's default value to something calculated. (Is there a way of defining a global PHP function I could call in the Default Value setting perhaps??)

Thanks,

C
cgphp 6/11/2012

Enter the session var in the "Default value" textbox of the Date field in the Edit dialog: http://xlinesoft.com/phprunner/docs/_edit_as__settings.htm#date