Copy link to clipboard
Copied
Warning I know just enough to screw things up!
Looking to hide 3 fields based on the condition (checked or unchecked) of a checkbox.
Here are the fields:
If cb_homeage is checked, the three texboxes (tb_...) would be hidden
Here is what I have that is absolutely not working.
cb_homeage/Actions/Mouse Up/run javascript
var fieldHide = event.target.isBoxChecked(0)?display.visable:display.hidden;
this.getField("tb_yearbuilt").display = fieldHide;
this.getField("tb_homeyear").display = fieldHide;
this.getField("tb_homeage").display = fieldHide;
One thing I am not sure about it the (and I'm sure I'm using the wrong terminology) checkbox identifier - so ...isBoxChecked(0) - not sure it's 0 (there are +/- 100 checkboxed and radio buttons)
Copy link to clipboard
Copied
The error is because cb_homeage is not defined (when there's no quotes around it it's a variable that hasn't been defined). It should be replaced with 0 to determine whether the box is checked in the Mouse Up action. You are also calling field names that do not exist in the rest of the script so there will more errors. However, since the checkbox "cb_homeage" has no other copies it's a lot easier to use the following script:
var fieldHide=event.target.value=="Off"?display.hidden:display.visible;
//set display of your fields to fieldHide, example:
this.getField("tb_homeage").display = fieldHide;
Copy link to clipboard
Copied
The zero is for the first "widget" of the field, meaning the first in a series of check boxes that are named identically. The widget numbers are in the order the fields were created starting with zero. If this check box is the only one, then the zero would be correct to identify this check box. However, your error is that you mispelled visible.
Copy link to clipboard
Copied
And that was a copy and paste :O/!!
How do I find the actual "ID" number for that check box?? There are 35+ check and radio button on this form page
Copy link to clipboard
Copied
In Prepare Form mode click the check-box you're interested it and it will be selected in the Fields list on the right. The number after "#" in that list is its index number in the group (note the numbers start from 0, not 1):
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If there's no # plus number in the fields panel, there is only one widget, so you would use the zero as you did originally.
Copy link to clipboard
Copied
Yes. Look at the page property of the field. If it's a number there's only one copy of it; If it's an array, there are multiple copies.
Copy link to clipboard
Copied
Sorry, still confused (not uncommon!). This is a 10 page form with 50+ checkboxes and 100+ radio buttons.
This page (page 1) has 2 checkboxes. I tried var fieldHide = event.target.isBoxChecked(0) & var fieldHide = event.target.isBoxChecked(1) - neither work.
Sure I'm missing something simple!?
Copy link to clipboard
Copied
Side note - here is the error that is being thrown:
ReferenceError: cb_homeage is not defined
1:AcroForm:cb_homeage:Annot1:MouseUp:Action1
Copy link to clipboard
Copied
Sorry, I was trying to call the check box by name in the error above
here is the error with isBox Checked(0):
TypeError: this.getField(...) is null
3:AcroForm:cb_homeage:Annot1:MouseUp:Action1
Copy link to clipboard
Copied
Your field is called "cb_homeage", not "cb_homepage"... Hence the error message you're getting.
Copy link to clipboard
Copied
@try67 I am not calling "cb_homepage" anywhere - what are you seeing that I'm not??
Copy link to clipboard
Copied
From the error message you posted... But you will need to post the full code (and/or the file) for further help with this.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The error is because cb_homeage is not defined (when there's no quotes around it it's a variable that hasn't been defined). It should be replaced with 0 to determine whether the box is checked in the Mouse Up action. You are also calling field names that do not exist in the rest of the script so there will more errors. However, since the checkbox "cb_homeage" has no other copies it's a lot easier to use the following script:
var fieldHide=event.target.value=="Off"?display.hidden:display.visible;
//set display of your fields to fieldHide, example:
this.getField("tb_homeage").display = fieldHide;
Copy link to clipboard
Copied
Thank you! Something I didn't realize.. Once Javascript his an error the script stops? Is there anything like an: onerror.resume?
Copy link to clipboard
Copied
- Yes.
- No, unless you catch the error in a try-catch clause, which you shouldn't really do. You should solve it.
Copy link to clipboard
Copied
Correct. All the scripts stop when an error is triggered. That's why you'll see "did you check the console for errors" a lot in the repsonses in this forum. When someone uploads a form and says "it doesn't work" the first thing I do is clear the console. Next I trigger a calculation, then I check the console. It's a good way to trouble shoot. As @try67 said, you can use try/catch, but all that will do is skip the error and you won't be able to find it.