Correct way to set Control field value at runtime?

What is the correct way to set the value of a field in a Control at runtime?

{fieldName} = $valueField;

If $valueField has a value this is the correct way. Best spot to use it, is the onload event.

Thanks Albert, but what would be the best way to set field when application is being Run? Have an AJAX button which runs PHP code and trying to set value of field when button is clicked. Strangely works on development environment but not on production environment?