Skip to main content
madeleinel22391508
Known Participant
April 18, 2016
Question

If statement before correcting for percentage

  • April 18, 2016
  • 2 replies
  • 2197 views

Hi,

I have a field (SCharge1) in which clients specify the sales charge (0-3%) applied. I would like to check to make sure that the amount entered is between 0 and 3 however, I have modified the percentage format as to divide the amount entered by 100 so that clients can enter 1 and it equals 1% so that clients do not get confused when filling out the form. I have done this by running a custom validation script:

if (event.value !== "") {

event.value = event.value / 100 ;

}

I was wondering if there was a way to check to make sure the field is between 0-3 and if not creating an error message to modify the field?  I am unsure whether to run the check before or after the validation script and whether to combine the scripts or add a separate option. This is what I tried to check the sales charge after but to no avail:

(function () {

  

    var v = getField("SCharge1");

   if(v >0.03){

   var resp = app.alert({cMsg: "Fund Code does not match the Fund Class selected, please revise.", nIcon:0});

}}

)

Any help would be much appreciated!

This topic has been closed for replies.

2 replies

sinious
Legend
April 20, 2016

You could even consider using an entirely different input type like a drop-down since your values are so controlled and seemingly simple.

madeleinel22391508
Known Participant
April 26, 2016

Unfortunately, I do not think a drop down will work as the value can be any value between 0 - 3% including decimals (1.5 ect.) however, maybe you could elaborate on your idea? Still might be a working solution.

sinious
Legend
April 26, 2016

The drop-down definitely won't work unless you had a small, fixed amount of values to choose from. At least it's not practical.

I only did a few things in PDFs regarding JavaScript for validation but before I open up a PDF and try what you're attempting, I'd like to really understand why you feel you need to divide the users input by 100 (e.g. 3 = 0.03)? You can calculate that at a later time and leave the users inputted number so it makes sense to them. If they put in [ 1.5 ]% and it instantly turns to what I think you're doing,  [ 0.15 ]%, that can be confusing to users.

Do you merely need this value to be used internally in your calculations or is it actually important to show the user the number divided by 100? What if they see their input divided by 100 and then the next time they use it, they put in 0.15 and you divide that by 100 again?

I'm trying to get to the behavior you really seek for this input.

Brad Lawryk
Legend
April 18, 2016
Inspiring
April 19, 2016

I believe this is an Acrobat JavaScript issue and might be better answered in the Acrobat JavaScript forum. Acrobat JavaScript does not completely work with web JavaScript and the JavaScript used in other Adobe products including Bridge .This continues to cause problems for non-Acrobat coders.