# Clear text field when clicked

**URL:** https://forum.kirupa.com/t/clear-text-field-when-clicked/285471
**Category:** flash
**Created:** [April 1, 2009, 9:37am UTC](https://forum.kirupa.com/t/clear-text-field-when-clicked/285471 "2009-04-01T09:37:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ruiganga](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ruiganga/32/3679_2.png) [@ruiganga](https://forum.kirupa.com/u/ruiganga)
#### Post date: [April 1, 2009, 9:37am UTC](https://forum.kirupa.com/t/clear-text-field-when-clicked/285471/1 "2009-04-01T09:37:09Z")

</div>

Hi

I have a code that clear textfield when you click inside. My problem is that I have to many text fields so i am trying to write some function that can be used for all the text fields.

What I can’t do is to add some other property to the textfield like I can do with any variable. So my code is:

// nome is a textField  
var nome:TextField;  
nome.text = “olá” // text displayed inside the text field  
var nomePreText = “olá”;

function clearTextField(e:Event) {  
if (e.currentTarget.text == e.currentTarget.name+“PreText”) {  
trace(e.currentTarget.name+“PreText”); // this trace nomePreText  
e.currentTarget.text = “”;  
} else {  
trace(e.currentTarget.name+“PreText”);  
trace(“campo já foi preenchido”);  
}  
}

nome.addEventListener(“focusIn”,clearTextField);

This is not working. If someone can give me a hint i’ll appreciate 🙂
