Is it possible to convert a user input in a text box to change within the same text box once the user entered/tabbed out?

Community Beginner ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

I am developing a scope sheet for a construction company.  I want to have the employee/user to get to the room size portion of the document to be able to put in: 5,3 to represent 5'3" but once they enter/tab out of that text box it converts to 5.25.  I can do last conversion (converting to a decimal) - I am stuck on having the "Feet,Inches" / "5,3" - represent 5'3" format.  I'm also up for any suggestions that would solve this issue any other way (and most likely easier since I always tend to make things complicated) - Thank you all in advance!

TOPICS
Acrobat SDK and JavaScript

Views

175

Likes

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

Most Valuable Participant , Dec 28, 2017 Dec 28, 2017
OK, then use this code as the field's custom validation script:var v = event.value;if (v!="") {    var parts = v.split(",");    if (parts.length==2) {        event.value = Number(parts[0]) + Number(parts[1])/12;    }}

Likes

Translate

Translate
Most Valuable Participant ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

Sure, it's possible, but do you want to change the actual value, or just how it is presented?

In other words, if they enter "5,3", move out of the field and then move back into it, should the value they edit be "5.25" or the original "5,3"?

Likes

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 ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

Thanks for the reply try67!

If they entered "5,3" move out and it should show "5.25" -  That would be amazing! Is it simple and I will add this to the list of things I over complicate/think?

Likes

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
Most Valuable Participant ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

I understood that, but that's not what I asked about... Let me phrase it differently: Are you planning to use this value in a calculation of some kind (in which case it needs to be a decimal number), or is it just to make it easier for the user to enter it in a format they're familiar with?

Likes

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 ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

I apologize try67

I will use the value for a calculation.  The first one will be to calculate the total square footage of the room after they follow up and enter the width.  Some of the employees have issues with conversion to decimals and I want to make it simpler for them also so they don't have to ask for a way to do the conversion themselves. 

Likes

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
Most Valuable Participant ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

OK, then use this code as the field's custom validation script:

var v = event.value;

if (v!="") {

    var parts = v.split(",");

    if (parts.length==2) {

        event.value = Number(parts[0]) + Number(parts[1])/12;

    }

}

Likes

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 ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

Thank you so much try67!!!! I'll try it out right away! Thank you!

Likes

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 ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

Hi again try67​ - I was able to get to running the code you corrected for me and I keep getting a syntax error (SyntaxError: syntax error 2: at line 3).  I checked for extra spaces and some one or two other things but I still have the error.  Any ideas/suggestions again are appreciated!

var v = event.value;

if (v!=!!) {

  var parts = v.split(",");

  if (parts.length==2) {

    event.value = Number(parts[0]) + Number(parts[1])/12;

  }

}

Likes

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
Most Valuable Participant ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

Why did you change the second line to this:

if (v!=!!) {

?

Likes

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 ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

LATEST

I have no idea.  I just copied and pasted directly from what you posted and noticed that it was different.  I think my kid was copying and re-writing code and copied incorrectly.  Sorry about that. 

Likes

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