So now we are ready to write the code to set the label


Now click the green double arrow button to generate and run the code



Click the submit button


Every time that you click on submit the date and time will be set the the actual date and time.


The initial screen is not looking nice. How to set the label_1 to a decent value? Well, one option is by setting the property in the property editor. But as this document is all about events, why not code it in an event? Already guessed? To set the value and label of the label field we can use the onCreate event. But instead of using $$ we need to use the $this variable.


Why? Well while creating the instance of the component is not available yet. The $this is used to reach the current component. So we’ll get:



This is the oncreate event of the button and the properties of the button itself is changed. So $this. The result will be:



What if you want to use $$? Actually you can achieve the same result if you use the onActivate event of the form like this:



This will give the same result?


Actually no. Remember, PHsPeed works in two cycles. The first cycle will trigger the onActivate, but the second cycle also. onSubmitForm will trigger both cycles causing the label and value to be overwritten in the second ajax cycle. So initializing should only be done in the first cycle. So to get this sample to work we need to check if we are in the submit or ajax stage.



If you generate and run, you will achieve the same result. It’s up to you what you prefer.