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

Need help converting numbers to letters

Community Beginner ,
Feb 08, 2018 Feb 08, 2018

Copy link to clipboard

Copied

I'm creating a PDF form to be used in a blood bank.  When I scan a number, from a blood bag, how can I convert it to text?  For instance, I want the numbers "5100" to convert to "O Pos".  Is there a Javascript that can do that?

TOPICS
PDF forms

Views

1.2K

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 1 Correct answer

Community Expert , Feb 08, 2018 Feb 08, 2018

Let's say the field with the numbers is called Text1, and the field where the text should appear is called Text2.

Use something like this as the custom calculation script for Text2:

var t1 = this.getField("Text1").valueAsString;

if (t1=="5100") event.value = "O Pos";

else if (t1=="5200") event.value = "O Neg";

else if (t1=="5300") event.value = "A Pos";

else if (t1=="5400") event.value = "A Neg"; // etc.

else event.value = "";

Of course, I just made up the values above... Replace them with the real ones

...

Votes

Translate

Translate
Community Expert ,
Feb 08, 2018 Feb 08, 2018

Copy link to clipboard

Copied

Do these numbers appear in a form field? If so, then it can be done using a custom calculation script, yes.

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 Beginner ,
Feb 08, 2018 Feb 08, 2018

Copy link to clipboard

Copied

Yes, they are scanned into a form field.  Can you post the custom calculation script?  Thanks!

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 ,
Feb 08, 2018 Feb 08, 2018

Copy link to clipboard

Copied

Let's say the field with the numbers is called Text1, and the field where the text should appear is called Text2.

Use something like this as the custom calculation script for Text2:

var t1 = this.getField("Text1").valueAsString;

if (t1=="5100") event.value = "O Pos";

else if (t1=="5200") event.value = "O Neg";

else if (t1=="5300") event.value = "A Pos";

else if (t1=="5400") event.value = "A Neg"; // etc.

else event.value = "";

Of course, I just made up the values above... Replace them with the real ones in your actual code.

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Thank you for sending the script.  Must I create two different fields, or is there a way to scan into a single field, and have the interpretation show up in that same field?  Or, can I overlay the two fields somehow?  This is a screen shot of the current form.  I don't like the drop down menu under the Blood Type column because it can't be scanned like the two fields prior to it in the same row (I already inserted a script to auto-tab from one field to the next).  I want to scan the blood type ("5100") in the "ABO1" field and have the interpretation of "O Pos" show up in the same spot (and then auto-tab to the next row).  Is that possible?

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 ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

I would use two fields. The first one can even be hidden.

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

OK.  How do I hide the first 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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

I'm obviously not a software engineer, I'm a clinical laboratory scientist, so I'm doing my best to understand the details, but I am an amateur at best.  I inserted the real ABO values in the code, and deleted the "// etc."  Was is correct to deleted the "//"?  And, when I paste it into the form, do I need to delete the numbers at the beginning of each line?

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

I asked those questions too soon.  I figured out how to hide the field, and to delete the numbers at the beginning of each line.  Thank you again, for that script!

Here is another question, though.  Can you write me a script that cleaves off the beginning character of whatever is scanned?  For instance, when I scan a blood identification number that is supposed to be W123456789123, it shows up as =W123456789123.  I want to automatically remove the "=".  Thanks!

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 ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

The problem is I'm not sure what kind of events the scanning processes triggers... If it's the same as entering the value manually into the field then you can use this code as the custom validation script:

event.value = event.value.replace(/^=/, "");

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Yes, the scanning process triggers the same event as entering the value manually.  I will try this script.

Back to the original script.  I can get it to convert the numerical value to the alphabetic value, but only when I'm editing the Text field properties.  I falsely assumed that it would work as I was scanning it.  I added the following script as a Custom Keystroke Script to move the cursor from one field to the next:

// Autotab to the "Comp  Code Row1" field

tab_next("Comp  Code Row1");

And it works for all the fields except for the ABO1 field.  Why would it only do the conversion when I'm editing it, and not after I've closed the form editing mode?

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 ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Because that doesn't trigger any events. The calculation event is only triggered when the value of a field is changed, or if you call the calculateNow method of the Document object.

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

LATEST

Ok, thanks for the clarification.  I appreciate all your help!

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