Label text in event handler

In this example, I have shown a workaround for getting the label text in event parameter. This workaround can be very useful in some situations.


Example demo:

To try the demo, click on submit button

Example Code:

function doGet() {

  var app = UiApp.createApplication();


  //Create a penel which will hold all the elements

  var panel = app.createVerticalPanel();


  //Create a label, also set a tag to that label. Tag value must be same as the label text

  var label = app.createLabel('This is my Label').setId('myLabel').setTag('This is my Label');

  var button = app.createButton('Submit');


  //Create a invisible label which will be visible after submit, 

  //and hold the tag value/label text

  var labelInfo = app.createLabel().setVisible(false).setId('labelInfo');


  //Create a handler for the button

  var handler = app.createServerClickHandler('showDates');

  //add the panel as a callback element




  //Add all the lements to the panel



  //Add the panel to the application


  return app; 


//this function will show the dates

function showDates(e){


  //get the active aplication

  var app = UiApp.getActiveApplication();


  //get the tag value which is equal to the label text

  var labelText = e.parameter.myLabel_tag;




  return app;