These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Clear default value of text field when clicked

craigatlantic
Registered: Nov 4 2009
Posts: 13
Answered

Hello! This may be really easy, but I just can't seem to figure out how to do this. I'm using Acrobat 9 pro.

I have a text field and the default value is "First Name". Right now a users can click on the field and manually delete the default value and then enter his/her name.

I'm sure there's a way to automatically clear the default value when the text field is clicked.

Also, I only want the field to clear, if the default value is there. So, if the user entered his name and later on clicked that same field, it shouldn't clear his/her entry.

finally, if the user deleted his/her entry, the default value should re-appear.

I hope there's a Javascript that can do all of this.

If anyone could help me, I would really appreciate it!

Craig

My Product Information:
Acrobat Pro 9.2, Windows
ditraub
Registered: Nov 13 2009
Posts: 11
If you open your form in Live Cycle you can add the following JavaScript to the field's enter and exit triggers which will remove your default text when you enter the field, and if left blank, will replace the default text when you exit the field.

Field.Reference::enter - (JavaScript, client)
if (this.rawValue == "Default Text.")
{
this.rawValue = null;
}Field.Reference::exit - (JavaScript, client)
if (this.rawValue == null)
{
this.rawValue = "Default Text..";
}
craigatlantic
Registered: Nov 4 2009
Posts: 13
Thanks for your fast reply!

I didn't use Life Cycle to create the form, and when I tried to open it there were error messages about needing to update the current javascript to be able to work with Designer.

Sorry I should have mentioned I have been using Acroform... Is there a way to do this in Acroform?

Thanks, and I really appreciate it.

Craig
revoxo
Registered: Jul 20 2009
Posts: 17
I'm sure someone will post something more elegant but the following seems to work well.

I've called the name field "TextField1".

In the Actions tab for the field properties
Choose the Mouse Down trigger, select "Run a Javascript" and enter the following code:

var f = this.getField("TextField1"); //get the text field
if (f.value == f.defaultValue) f.value = ""; //if field value = the default, then clear it

Then in the Actions tab for the field properties
Choose the On Blur trigger, select "Run a Javascript"and enter the following code:

var f = this.getField("TextField1"); //get the text field
if (f.value == "") f.value = f.defaultValue; //if field value = empty, then restore the default

If the field is cleared it will restore the default if you click elsewhere or tab to the next field.

Hope this helps :0)
craigatlantic
Registered: Nov 4 2009
Posts: 13
Thank you so much... worked perfectly!

Craig
colmdoyle
Registered: Feb 15 2010
Posts: 2
Hello, I have designed a simple form using adobe livecycle and would like to implement the same function craigatlantic has discribed "Clear default value of text field when clicked"

I have tried using the code above from both helpful users but have had no luck in getting the script to clear out the default value of a text field when clicked, and returning default value if left blank.

Can anyone else help with this issue.


Thanks
Colm
colmdoyle
Registered: Feb 15 2010
Posts: 2
anyone?