Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...On your site I feel quite confident that the contacts and feedback will make my life a little less hectic..."

Geography

Where in the world do Tek-Tips members come from?

How to add grayed out text to a PDF text fieldHelpful Member!(3) 

dark2 (TechnicalUser)
22 Feb 12 10:41
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,

MarkWalsh (Programmer)
23 Feb 12 9:34
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.
dark2 (TechnicalUser)
23 Feb 12 13:37
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!

MarkWalsh (Programmer)
23 Feb 12 14:11
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.
dark2 (TechnicalUser)
23 Feb 12 15:57
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,

MarkWalsh (Programmer)
23 Feb 12 20:27
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')
dark2 (TechnicalUser)
24 Feb 12 10:32
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.

Helpful Member!(3)  MarkWalsh (Programmer)
24 Feb 12 11:21
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'
dark2 (TechnicalUser)
24 Feb 12 12:34
Hi MarkWalsh,
Thank you! Thank you! Thank you!
It's working perfectly! Thanks for being soooo patient!
Have a wonderful weekend!
 

moneer99 (TechnicalUser)
10 Jul 12 21:41
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 ?
moneer99 (TechnicalUser)
10 Jul 12 22:08
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
jjbears2k12 (Programmer)
4 Dec 12 16:14
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

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!

Back To Forum

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