Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Force input whole number
  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.

Force input whole number

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


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Topic: Force input whole number
    Posted: 13 Aug 2015 at 3:00pm

Hello all,

As you'll noticed I'm  Javascript newbie.

How can I force that field have to field in with a whole number (no rounding up). If a user wants to fill in a number with a decimal, an allert pops up "Please fill in a whole number)

Somebody wants to help with a javascript to do this?

Thank you
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4113
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 13 Aug 2015 at 6:46pm
JavaScript has the Math.floor() function to truncate the value to the next lower whole number.
 
In the custom JavaScript calculation one can input to force the value to the closest next lower integer.
 
event.value = Math.floor(event.value);
 
If you want a custom validaton:
 
if(event.value != Math.floor(event.value) {
app.alert("Please fill in a whole number", 1, 0);
this.resetForm([event.target.name]);
event.rc = false;
}
 
One could also use a script to limit the keystroke input to digits only.

 
Back to Top
Maureen View Drop Down
New Member
New Member


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Posted: 14 Aug 2015 at 3:51pm
Thks for your reply, but I've used your script in the custom validation, bu no alerts popsup when filling in a value with decimals. I used this script:

if(event.value != Math.floor(event.value) {
app.alert("Please fill in a whole number", 1, 0);
this.resetForm([event.target.name]);
event.rc = false;
}

What have I done wrong?
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4113
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 14 Aug 2015 at 4:55pm
I get an error. There is a missing parenthesis in the condition statement.
 
if(event.value != Math.floor(event.value)) {
app.alert("Please fill in a whole number", 1, 0);
this.resetForm([event.target.name]);
event.rc = false;
}
 
Back to Top
Maureen View Drop Down
New Member
New Member


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Posted: 17 Aug 2015 at 10:24am
Thank you. It works!!
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.031 seconds.