×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

How to add grayed out text to a PDF text field

How to add grayed out text to a PDF text field

(OP)
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,

RE: How to add grayed out text to a PDF text field

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.

RE: How to add grayed out text to a PDF text field

(OP)
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!

RE: How to add grayed out text to a PDF text field

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.

RE: How to add grayed out text to a PDF text field

(OP)
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,

RE: How to add grayed out text to a PDF text field

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')

RE: How to add grayed out text to a PDF text field

(OP)
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.

RE: How to add grayed out text to a PDF text field

3
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'

RE: How to add grayed out text to a PDF text field

(OP)
Hi MarkWalsh,
Thank you! Thank you! Thank you!
It's working perfectly! Thanks for being soooo patient!
Have a wonderful weekend!
 

RE: How to add grayed out text to a PDF text field

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 ?

RE: How to add grayed out text to a PDF text field

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

RE: How to add grayed out text to a PDF text field

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close