Input Textfield hint


/ Published in: ActionScript 3
Save to your folder(s)

Showing an input hint in the TextField itself,
hiding it on focus/input,
and showing it again when the input is left empty.


Copy this code and paste it in your HTML
  1. var hint:String = "dd-mm-yyyy";
  2. txtDate.text = hint;
  3.  
  4. txtDate.addEventListener(FocusEvent.FOCUS_IN, focusIn);
  5. txtDate.addEventListener(FocusEvent.FOCUS_OUT, focusOut);
  6.  
  7. private function focusIn(evt:FocusEvent):void
  8. {
  9. if (evt.target.text == hint) txtDate.text = "";
  10. }
  11.  
  12. private function focusOut(evt:FocusEvent):void
  13. {
  14. if (evt.target.text == "") txtDate.text = hint;
  15.  
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.