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

Follow up to checkboxes causing a text box to populate

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Answered

I solved my earlier problem with trying to get checkboxes to populate a text field. The code below worked well, but I have one question:
I noticed that when I uncheck the checkbox, I get "NA" in the text box. I need for the text boxes to be blank when the checkboxes are unchecked, so I removed NA from between the quotation marks in the code, and then the NA letters were no longer visible when the boxes were unchecked. It works, but is it "bad" code? Is there a cleaner way to have the text boxes be blank when the check boxes are unchecked?

event.value = this.getField('Check Box1').value;
if (event.value =='Off') event.value = 'NA'; // adjust for 'Off' or unchecked value

becomes

event.value = this.getField('Check Box1').value;
if (event.value =='Off') event.value = ''; // adjust for 'Off' or unchecked value

Thanks,
Amy

Amy Wheeler
avalonprojectpartners.com

My Product Information:
Acrobat Pro 9.2, Macintosh
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Without knowing when event.value gets assigned back to the text field value, this could be just as efficient as anything else. If it happens after this event exits, or if it is just a reference to the field value itself, then this is just as efficient as anything I can think of.

I think I remember seeing the rest of your code from yesterday and it had to do with assigning a value for the text field based on the value of the checkboxes, right (translating some number to a string)? If that is the case, how is it that event.value here seems to be a reference to a text field event? Wouldn't this code be in the checkboxes?

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

awheeleravalon
Registered: Sep 15 2009
Posts: 27
The goal was to have a form user check either a yes or no checkbox. If they check yes, the word "Yes" appears in the nearby text box, if they check no, then "No" appears in another nearby text box. I was given that string of code (i know little about code) to put in the Calculate property of the text field, and it just picks up the value of the yes or no checkbox. What happened, of course, is that when nothing is checked, the text field shows "NA" and I needed it to be completely blank. So, yes, I guess it's just a reference to the field value. I was just concerned that because I don't know much about code that I had done something I would regret later. If that's not the case, then I think I'm good to go.

Amy Wheeler
avalonprojectpartners.com

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
While I see the advantage of the simplicity of putting this code in the calculate of the textbox, I would never put it there. The problem is that calculations are hugely inefficient (they recalculate every time ANY field changes value). I would select all the checkboxes or radio buttons involved and add a MouseUp action with this code (change for your Text Box name):

var oField = getField("Text1"); // adjust for your text box name
if (event.target.value =='Off') oField.value = ''; // adjust for 'Off' or unchecked value
else oField.value = event.target.value;

Good Luck,
Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Thanks, Jim. Like I said, the coding thing is totally new to me. I tried to do what you said, but when I went to the Actions dialog box for my checkbox, I can't paste any text in the Actions box and the buttons - Up - Down - Edit - Delete are greyed out. Exactly here and how do I place the code?
THEN, the client has decided they want to do this with radio buttons so that no one can check both Yes and No for the same question. So, same question and problem, but I need to be able to select one of two radio buttons and get text in a text box. How do I do that?

Amy Wheeler
avalonprojectpartners.com

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
In the "Add an Action" Group, near the top, choose Mouse Up from the "Select Trigger" dropdown, then choose "Run a Javascript" from the "Select Action" dropdown, then click the "Add" button.

I would also suggest selecting all of the checkboxes in the group at once. That way, you only have to paste the code in once for each group rather than once for each checkbox.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Will this same code work for Radio buttons? The client has decided they want to do this with radio buttons so that no one can check both Yes and No for the same question.

Amy Wheeler
avalonprojectpartners.com

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Yes.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Thanks. I'm going to try it later today as soon as I crawl out from under other projects!!

Amy Wheeler
avalonprojectpartners.com

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Hi Jim:

I had a chance to test the code on my form, and it works fine, except for the following:
Text boxes start out blank, and when "Yes" Radio button is checked, "Yes" appears in the text box. If I then check the "No" radio button, the word "No" appears in its text box, and the Yes radio button goes blank, but the word "Yes" remains in the associated text box. I thought this bit of code would give me a blank box when its associated Radio Button is Off.

if (event.target.value =='Off') oField.value = ''; //


Is that not correct?

Amy Wheeler

Amy Wheeler
avalonprojectpartners.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The value of the "radio button" group is the value of selected radio button or "Off" is none of the buttons is selected. Further, the text field will only update when there is a "Mouse Up" action for any of the radio buttons in the group. You could also add the script to the "On Blur" (field exit) or "Mouse Exit" actions.

If you have more than one text box associated with the radio button group, then you would need to adjust each box as required for the condition tested. So you probably should clear all the fields updated by the radio button group before assigning the values for the 'Mouse Up' action. But with the code in the "mouse up" action the text "Off" will most likely never appear in the text box.

George Kaiser

awheeleravalon
Registered: Sep 15 2009
Posts: 27
Good Morning: Given my complete ignorance of javascript, I am still having some problems that I don't understand. Could I send you a little sample PDF with what I've done so far so that you can tell me what I'm doing wrong? It's probably something really simple, but I'm stumped.

Amy Wheeler
avalonprojectpartners.com

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Use the e-mail link on my profile.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com