Expand my Community achievements bar.

SOLVED

Percent Display patern

Avatar

Level 7

I am using the follow patern for a numeric field to display a percent number: num{zzzz9.999'%'}

What kind of pattern or script I can use so the field does not allow user  to enter percents more than 100%?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Not sure what the problem might be but maybe you can try something like;

if ($ <> null and ($ < 0 or $ > 100)) then

xfa.host.messageBox("More than 100%. Please change the percent.")

xfa.host.setFocus($.name)

endif

View solution in original post

3 Replies

Avatar

Level 10

You could add some code in the change event of the field like;

var

newValue = parseInt(xfa.event.newText);

if

(isNaN(newValue) || newValue < 0 || newValue > 100)

    xfa.event.change

= "";

But this means that if they enter a number like 99 and want to change it to a number like 91 they will have to delete the second nine before they can type the 1.

Bruce

Avatar

Level 7

I try to use this script on exit without any luck...

What can be wrong?

Thanks

if (form1.Page1.NumericField1.rawValue <=100) then
// good
$.rawValue = $.rawValue;

else

xfa.host.messageBox("More than 100%. Please change the percent.");
xfa.host.setFocus($.name);
endif

Avatar

Correct answer by
Level 10

Hi,

Not sure what the problem might be but maybe you can try something like;

if ($ <> null and ($ < 0 or $ > 100)) then

xfa.host.messageBox("More than 100%. Please change the percent.")

xfa.host.setFocus($.name)

endif