Print Page | Close Window

Add a dash and the number count to be from 4 to 8

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=4016
Printed Date: 07 Dec 2019 at 10:07am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Add a dash and the number count to be from 4 to 8
Posted By: krosal
Subject: Add a dash and the number count to be from 4 to 8
Date Posted: 08 Oct 2018 at 10:31am
Hello, I'm working on a PDF form in Adobe XI and need to have a text box formatted as 99-99999. I just found out that the number can vary from 99-9 to the full 99-99999. I found some code and modified it for my use, but it fails at the last line. I'm hoping it's an easy fix. Please see the following code.

// call from format script
// format entry to 99-9 or 99-99 or 99-999 or 99-9999 or 99-99999
function twoDash1() {
//Get the value the user entered, as a string
var s = event.value;
//do nothing if the field is blank
if (!s) return
//allow 4 to 8 characters
if (s.length === 4 || s.length === 5 || s.length === 6 || s.length === 7 || s.length === 8) {
// Determine the format string to use
var fs = "99-9";
if(s.length===4)fs+="9";
if(s.length===5)fs+="99";
if (s.length === 6) fs+="999";
if (s.length === 7) fs+="9999";
if (s.length === 8) fs+="99999";
//display the formated value
event.value = util.printx(fs, s);
} else {
// let the user know something is wrong
app.alert("Please Enter 4 to 8 characters.", 4);
}
// Call from Keystroke script
// Limit entry to digits only
function DigOnlyKS() {
// Get all that is currently in the field
var val = AFMergeChange(event);
//Reject entry if anything but digits
Event.rc AFExactMatch(/\d*/, val);
}


I receive the following error;

SyntaxError missing; before statement 30: at line 31

Also, at the end of line;

app.alert("Please Enter 4 to 8 characters.", 4);


the original code had a 3 instead of 4, I'm not sure what this is for? I thought that maybe it was for the test quantity, so I change it to a 4. Either way, it still fails at the last line where the } input is.


Thank you,
Kelly




Replies:
Posted By: krosal
Date Posted: 08 Oct 2018 at 12:23pm
above should say "text quantity" instead of "test quantity"

for mention of;
the original code had a 3 instead of 4, I'm not sure what this is for? I thought that maybe it was for the test quantity, so I change it to a 4. Either way, it still fails at the last line where the } input is.


Posted By: Rob Lyman
Date Posted: 10 Oct 2018 at 8:52pm
For one thing, your curly braces are not balanced: the opening '{' for the function twoDash1() is never balanced with a closing '}'. Adding a '}' just above the line:

// Call from Keystroke script

should balance things out.

Also, since you never have a call for the function DigOnlyKS(), I think you could delete it (although it does no harm to leave it in).



-------------
Rob Lyman
Software Engineer
http://www.datalogics.com


Posted By: krosal
Date Posted: 11 Oct 2018 at 8:23pm
Hello,

Wonderful, I will give this a try and let you know the results.

I surely appreciate your help!

Thank you,
Kelly


Posted By: krosal
Date Posted: 12 Oct 2018 at 3:56pm
Hello,
It still is not working.
 
I have looked at the code that I currently have and it does have the bracket in question located in the recommended spot that you have mentioned. I'm thinking that possibly the copy/past into the web portal changed something.
 
It still fails on the last line where the } bracket is. If I move the bracket down (1) line, it then fails on the blank line, right below "Event.rc AFExactMatch((/\d*/, val);"
 
If you notice the double parentheses Event.rc AFExactMatch((/\d*/, val); the code that I have only has (1), so copying into the web somehow creates the extra one. Maybe that was why the curly bracket was missing when I copied it over?
 
// call from format script
// format entry to 99-9 or 99-99 or 99-999 or 99-9999 or 99-99999
function twoDash1() {
//Get the value the user entered, as a string
var s = event.value;
//do nothing if the field is blank
if (!s) return
//allow 3  to 8 characters
if (s.length === 4 || s.length === 5 || s.length === 6 || s.length === 7 || s.length === 8) {
// Determine the format string to use
var fs = "99-9";
if(s.length===4)fs+="9";
if(s.length===5)fs+="99";
if (s.length === 6) fs+="999";
if (s.length === 7) fs+="9999";
if (s.length === 8) fs+="99999";

//display the formated value
event.value = util.printx(fs, s);
} else {
// let the use know something is wrong
app.alert("Please Enter 3 to 8 characters.", 3);
}
// Call from Keystroke script
// Limit entry to digits only
function DigOnlyKS() {
// Get all that is currently in the field
var val = AFMergeChange(event);
//Reject entry if anything but digits
Event.rc AFExactMatch((/\d*/, val);
}
 
Thank you,



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net