Reputation: 11
Creating an interactive pdf document that should allow the user to fill in the annotation to whomever it needs to be send.
Example: Hi [your name here],
Should be filled in as such: Hi Oliver Baker,
Now I've been using this piece of code to make sure the default text disapears as soon as it is clicked
ON FOCUS
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
ON BLUR
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
Now the default text disappears how I like it, however I would like to remain the comma behind the value that has been filled in.
I'm a tad of a noob to coding so I request your help.
//<Document-Level>
//<ACRO_source>highlight</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:highlight ***********/
var rths = app.runtimeHighlight ;
app.runtimeHighlight = false ;
//</ACRO_script>
//</Document-Level>
//<AcroForm>
//<ACRO_source>Date:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Date:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Date:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Date:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Location:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Location:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Location:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Location:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Student name:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Student name:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Student name:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Student name:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Time:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Time:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>Time:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Time:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>boss's name:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:boss's name:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
event.target.value = "";
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>boss's name:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:boss's name:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>
Upvotes: 1
Views: 741
Reputation: 4907
You can make this a lot simpler. Remove the onFocus and onBlur scripts and add the following code to the custom format script. The value of the field will be whatever is entered into the field (the name of the person or an empty string) but the appearance on the form will be the string you concatenate. In the code below, the event is the format event so the event.value will be the string that's used to generate the appearance. The event target is the field, so the event.target.value is the actual value of the field. The if statement is there just to add a space in the case where the name is filled and position the comma correctly when it's empty.
if (event.target.value != "") {
var pad = " ";
}
else {
pad = "";
}
event.value = "Hi"+pad+event.target.valueAsString +","
An empty field will show "Hi,". If the field value is "Joel Geraci", the string "Hi Joel Geraci," will appear on the form.
Upvotes: 1
Reputation: 1651
I don't think you're showing the code where they enter their input, but either way, why not just concatenate the comma onto the string?
event.target.value = event.target.value + ','
Upvotes: 0