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

Javascript to clear identified field

rkpdfmaker
Registered: Jul 29 2010
Posts: 8
Answered

Hi,

I have an Interactive PDF which I have created and need to control a group of radio button (check box) fields. I currently have it set so that the user can only check one of the boxes, the problem is that they also have the option of filling out a free text field - if this field is selected it needs to clear any check boxes that have been selected.

Any assistance or advice wuld be gratefully received.

thanks

rkpdfmaker
designer

My Product Information:
Acrobat Pro 9.0, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Why not have a radio button or check box before the other text field. The other text field would be locked until this check box or radio button is selected.

If you want to test for text, try testing for not equal to a null string and then setting the check box or radio button group to 'Off' or reseting the form and selecting only the check box or radio button group?

if(event.value != "") {this.resetForm("Check Box Group Name");}

George Kaiser

rkpdfmaker
Registered: Jul 29 2010
Posts: 8
OK, I can now clear the check boxes with this:

if(event.value != "Text58") {
this.resetForm("Radio Button57");
}

but it is now not possible to enter text into field 58. What am I doing wrong here?

rkpdfmaker
designer

klwalsh611
Registered: Sep 10 2009
Posts: 28
gkaiseril - how would this script work if I needed to reset several field values if a radio button were unchecked after originally being checked?

Scenario - order form with Ship To and Bill To fields. The user has an option to check a box if the Bill To is the same as the Ship To and the corresponding fields are populated with the information. If the user changes their mind and unchecks the box, they expect the Bill To fields to reset to blank but I don't know how to script that step. Any guidance is GREATLY appreciated!

I work on both a Mac and Windows using Acrobat Pro 9 Extended.

Regards
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
rkpdfmaker wrote:
OK, I can now clear the check boxes with this:if(event.value != "Text58") {
this.resetForm("Radio Button57");
}

but it is now not possible to enter text into field 58. What am I doing wrong here?
Not only do you need to clear the check box, but you need to change the read only property of the associated text field to allow entry. You may also want to provide a script that will reset the text field's read only property if the user unchecks the check box.

George Kaiser

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
klwalsh611 wrote:
gkaiseril - how would this script work if I needed to reset several field values if a radio button were unchecked after originally being checked?Scenario - order form with Ship To and Bill To fields. The user has an option to check a box if the Bill To is the same as the Ship To and the corresponding fields are populated with the information. If the user changes their mind and unchecks the box, they expect the Bill To fields to reset to blank but I don't know how to script that step. Any guidance is GREATLY appreciated!

I work on both a Mac and Windows using Acrobat Pro 9 Extended.

Regards
Yes, but you need to use an array of field names.
this.resetForm([ "Text Field1", "Text Field2", "Text Field3" ]);

George Kaiser

klwalsh611
Registered: Sep 10 2009
Posts: 28
gkaiseril - i applied that script to my checkbox but had to reverse my thought process to have the condition be if the box value didn't equal Yes, then resetForm on the array, else populate the fields with the corresponding values.

Thank you so much!