This topic is locked
[SOLVED]

 Enabling a field before save

5/9/2011 4:16:02 AM
PHPRunner General questions
jclabuschagne author

Hi, PHPRunner 5.3 Build 7474
I have a online registration form database that has many fields that, if selected, update a TotalCost field. I created the code on the javascript onload event, this works successfully. What I need is to disable the TotalCost field so it won't be edited by the user.
I have used the javascript var TotalCost = Runner.getControl(pageid, 'TotalCost'); TotalCost.setDisabled(); statement to do this, and it works.
The problem I have is:
If I save the record, the TotalCost field isn't written to the database, and I tested if I remove the above statement, the TotalCost field is saved successfully.
How can I enable the TotalCost field just before writing to the database, and then disable it again?
A more detailed description of the database:
I have about 20 fields that update the TotalCost field, example: Do you require transport to the airport at the cost of 450.00? if checked, update the TotalCost field with 450.00, if unchecked, update the field with -450.00
TotalCost should not be edited by the user, but should be written to the database.
I have tried making the TotalCost a readonly field, but then my javascript doesn't work on the field (it doesn't update TotalCost)
Any suggestions?

Sergey Kornilov admin 5/9/2011

You can add your code that enables this field to beforeSave event.
Check this article for inspiration:

http://xlinesoft.com/phprunner/docs/add_custom_field_to_form.htm

jclabuschagne author 5/10/2011



You can add your code that enables this field to beforeSave event.
Check this article for inspiration:

http://xlinesoft.com/phprunner/docs/add_custom_field_to_form.htm


Thanks that helped me alot!
Added this code to the onload event:



this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
TotalCost.setEnabled();

return true;

});