Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Add a dash and the number count to be from 4 to 8
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

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

 Post Reply Post Reply
Author
krosal View Drop Down
New Member
New Member


Joined: 08 Oct 2018
Location: Wisconsin
Points: 4
Post Options Post Options   Quote krosal Quote  Post ReplyReply Direct Link To This Post Topic: Add a dash and the number count to be from 4 to 8
    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



Edited by krosal - 08 Oct 2018 at 10:54am
Back to Top
Sponsored Links


Back to Top
krosal View Drop Down
New Member
New Member


Joined: 08 Oct 2018
Location: Wisconsin
Points: 4
Post Options Post Options   Quote krosal Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Rob Lyman View Drop Down
New Member
New Member
Avatar

Joined: 12 May 2015
Location: Chicago
Points: 27
Post Options Post Options   Quote Rob Lyman Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
krosal View Drop Down
New Member
New Member


Joined: 08 Oct 2018
Location: Wisconsin
Points: 4
Post Options Post Options   Quote krosal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
krosal View Drop Down
New Member
New Member


Joined: 08 Oct 2018
Location: Wisconsin
Points: 4
Post Options Post Options   Quote krosal Quote  Post ReplyReply Direct Link To This Post 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,
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.016 seconds.