• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

javascript a value from another field to another field

Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Hello,

 

I have a field that is a number that results (when entered) 999-99-9999.  This is field "1a".  I'm trying to get this result to show up in another field "a14a7" without the "-" between the numbers so it all comes together as 999999999.  This is the script i wrote, which is pulling the number entered but my result still has the hyphens.  Can anyone help me with this?

 

if(this.getField("1a").value)
{event.value=this.getField("1a").valueAsString}
else
{event.value=this.getField("").valueAsString}

 

TOPICS
How to , JavaScript , Modern Acrobat , PDF forms

Views

183

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 13, 2024 Nov 13, 2024

Try this

 

if(this.getField("1a").value)
    event.value=this.getField("1a").valueAsString.replace(/\-/g,"");
else
    event.value=this.getField("").valueAsString;

 

 

Votes

Translate

Translate
Community Expert , Nov 13, 2024 Nov 13, 2024

Delete the script in "a14a7".  

Only the validation script in "1a" is needed. This validation script moves the data in "1a" into "a14a7".

 

 

Votes

Translate

Translate
Community Expert ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Try this

 

if(this.getField("1a").value)
    event.value=this.getField("1a").valueAsString.replace(/\-/g,"");
else
    event.value=this.getField("").valueAsString;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

PERFECT!!!  Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

If you have a lot of calculations, then form performance could be improved by using a Validation script for this action instead of a Calculation script.  Calculation scripts are run every time any field on the for is changed, whereas the Validation is only run when the specific field is changed. This solution works because field "a14a7" only get it's value from a single field. So that value can be pushed directly from the source field. 

 

To do this, delete the calculation on field "a14a7", and then add this script to the Custom Validation script on "1a";

 

if(event.value)
    this.getField("a14a7").value = event.value.toString().replace(/\-/g,"");
else
    this.getField("a14a7").value = "";

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Yes, i am having an issue.  The result is pulling where i want it go.  I even put in the validation script you suggested.  The is, if i delete the number that was typed in "1a" it is not clearing in the other field.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

try using just this code in the validation script for 1a, and make sure the name of the destination field ("a14a7") is correct, and that the original calculation script is deleted:

 

this.getField("a14a7").value = event.value.toString().replace(/\-/g,"");

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Still not working.  When enter the number in the field the first time, it seems to be working.  When i delete it the number just stays.  Here is the script i put in "a14a7":

 

if(this.getField("1a").value)
event.value=this.getField("1a").valueAsString.replace(/\-/g,"");
else
event.value=this.getField("").valueAsString;

 

and here is validation i put in:

 

this.getField("a14a7").value = event.value.toString().replace(/\-/g,"");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Delete the script in "a14a7".  

Only the validation script in "1a" is needed. This validation script moves the data in "1a" into "a14a7".

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

Wow, that was very confusing and cool once i got my mind around it!!!

 

I think i'm getting this now.  If, i didn't want to get rid of the hypens how would i change the script and the validation?  So mirrorr with the script and validation what is in "1a"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

argh.  When i deleted the number that was in 1a it did not clear out of a14a7

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

LATEST

ok.  it is in fact working!  ty;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines