These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Changing text field format when a radio button is selected

Bryan Thatcher
Registered: Oct 5 2011
Posts: 1

I have a field that accepts 9 numbers that have to be formatted to match a SS number 999-99-9999 or an EI Number 99-9999999
 
I originally just did a hide field when the radio button was selected but then it requires you to reenter the 9 digits. So now I'm trying to change the formatting of the field when the radio button is selected. this is where I've gotten and it just ain't working. any insight is much appricaiated.
 
as a Custom Format Script:
 
//see what radio button is selected
if (getField("Type").value = "SSN")
{
var v = "999999999";
v = util.printx("999-99-9999", v);
console.println(v);
}
else if (getField("Type").value = "EIN")
{
var v = "999999999";
v = util.printx("99-9999999", v);
console.println(v);
}

Fusebox Inc
An Internet Agency in New York City

My Product Information:
Acrobat Pro 10.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The value you need to modify is the value the user entered (event.value), not some arbitrary value you defined yourself (the v-variable in your code).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Hi,

you should download and install the Free Toolbar for Acrobat (Validation without code!): http://www.formrouter.com/

==> Create 2 fields sharing the same name (and the same value), one for each kind of formating, then you just have to manage show/hide fields in the radio buttons actions.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You need to use the correct JavaScript comparative operator. "=" is the set operator. While "==" is one of the equal to operators.

Rather than using the 'util.printx' method I would look at using the RegExp object for use in performing the keystroke validation, formatting, and validating JavaScripts.

For using Radio Buttons with the EIN assumed as the default button:

// set EIN format string
var cFormat = "99-9999999";
//see if SSN button selected
if (this. getField("Type").value == "SSN") {
// set SSN format string
cFormat = "999-99-9999";
}
// format the value for the field
event.value = util.printx(cFormat, event.value);

There is also no reason why one could not just use a single check box to inidcate that the Tax Payer ID is an SSN and it is assumed that the default format is EIN.

You could also not use a default checked field and lock the Tax Payer ID field until one of the radio buttons is selected. Change the radio button will not change the format of the entered text. This could be fixed by using a document level function to return the formatted string when the 9 digit number and type of formatting needs to be done.

George Kaiser

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
King George!

It's about another purpose and another kind of formatting, but as we say here : "you removed a spine from my foot".
Thanks.

:-)
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
King gkaiseril : can't you use a nicest Profile Picture ?
Yours looks like a mugshot…
;-)