Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add grayed out text to a PDF text field 3

Status
Not open for further replies.

dark2

Technical User
Sep 11, 2006
44
US
I want to create a form where some of the fields have a "tip" displayed within the field but once the user clicks to input data that "tip" disappears to allow entry data. For example if I ask for a phone number I want displayed within the field in light gray "XXX-XXX-XXXX". Once the user clicks the "XXX-XXX-XXXX" disappears to allow him/her to input the data. How can I do this?
Hope it's clear.
Thanks,

 
Here's what I use. I set the default value for the field to be whatever instructions I want displayed (i.e. 'Enter a date here... xxxxxxxx'). Add the following code to the document javascript:

function formatFieldDefaultValue () {
if (event.value == "" || event.value == event.target.defaultValue) {
event.target.display = display.noPrint;
event.value = event.target.defaultValue;
} else {
event.target.display = display.visible;
}
}

Then for each field that you want to display the default value, enter the following into the 'Custom Format Script':

formatFieldDefaultValue ()

If the field is empty, it will display the 'default' value. It also will not print the default value, you can turn those lilnes off if you desire, and/or set the field's text color.
 
Hi MarkWalsh,
One question. I did it all but when I click on the field the default value doesn't disappear. I have to manually deleting the entire default value in order to input data.
Is this how it's supposed to be? I am wondering if I did something wrong.
Thanks again!

 
Yeah, that's how my customer wanted his to work. Setting the Default Value puts that value into the field, you can clear the text field contents after you set the default, and it would do what you want, but if the user resets the form, it will put the default back into the field.

You can put the following directly into each field's format script (You will need to change the value for each field):

if (event.value == "") {
event.target.display = display.noPrint;
event.value = 'Please enter a date XX/XX/XXXX';
} else {
event.target.display = display.visible;
}


This way the field will be empty when the user enters the field, and will only display the instructions if the field is blank. If all of your fields will display the same message, you can just change my original function with the code above.
 
I am assuming I was supposed to replace the

function formatFieldDefaultValue () {
if (event.value == "" || event.value == event.target.defaultValue) {
event.target.display = display.noPrint;
event.value = event.target.defaultValue;
} else {
event.target.display = display.visible;
}
}

with

if (event.value == "") {
event.target.display = display.noPrint;
event.value = 'Please enter a date XX/XX/XXXX';
} else {
event.target.display = display.visible;
}

right? The results are still the same. It doesn't disappear.
Thanks again,

 
Clear the default value from the field, put the following in the 'Custom Format' field for every date field that you want to display the message for:

formatFieldDefaultValue ()


And put the following in a document level script:

function formatFieldDefaultValue () {
if (event.value == "") {
event.target.display = display.noPrint;
event.value = 'Please enter a date XX/XX/XXXX';
} else {
event.target.display = display.visible;
}
}


That should do what you want. Make sure you clear the contents from all of the fields (you can 'clear form')
 
Hi MarkWalsh,
It didn't work again. I even deleted all I've done before and created a new field but still not working. The "Please..." appears but when I click the field still shows the text.

 
Did you put the code in the field's 'Custom Format Script' or the 'Custom Calculation Script'?

IF you put it in the calculation script, remove it from there, and go to the 'Format' tab, select 'Custom' from the 'Select format getegory' dropdown, then enter it into the 'Custom FOrmat Script'
 
Hi MarkWalsh,
Thank you! Thank you! Thank you!
It's working perfectly! Thanks for being soooo patient!
Have a wonderful weekend!


 
great script Mr. MarkWalsh but the default value in the script doesn't appear when printing ... can you help me to make it -in addition to its great function- printable values ?
 
I did it with a little modification just replace noPrint with visible .. it was very easy ..thanks our programmer and thanks for topic publisher [smile]
 
Thanks Mark,

Saved the day. I was looking for the function that could display a value when printed and here I found your post. "event.target.display = display.visible;" worked like a charm.[thumbsup]

JJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top