Copy link to clipboard
Copied
I have a number of places in my form where checkboxes make another field visible/hidden. I started coding each checkbox with a Mouse Up script:
var pop = this.getField("A1.Text.0")
if (event.target.value == "Yes") { // Is the check box selected?
pop.hidden = false // Yes: make the form fields visible
}
else { // No: Hide the form fields again
pop.hidden = true
}
However it seems clear that the most efficient approach would be a document level script that I can call wherever it is needed. I found this sample script that seems a little more efficient than mine and I'm trying to adapt it to document level:
var showHide = event.target.isBoxChecked(0) ? display.visible : display.hidden;
this.getField("A1.Text.0").display = showHide
It seems like this should be written as a function rather than as a variable definition so I tried this:
function showHide(fieldPeek)
{
event.target.isBoxChecked(0) ? display.visible : display.hidden;
this.getField(fieldPeek).display = showHide
}
So then the Mouse Up event would be:
function showHide("A1.Text.0")
But I'm missing something and I'm not sure what.
Try like this:
function showHide(fieldPeek){
this.getField(fieldPeek).display = event.target.isBoxChecked(0) ? display.visible : display.hidden;}
Copy link to clipboard
Copied
Try like this:
function showHide(fieldPeek){
this.getField(fieldPeek).display = event.target.isBoxChecked(0) ? display.visible : display.hidden;}
Copy link to clipboard
Copied
That worked perfectly!! How would I write it to toggle read only for a field? This didn't work:
function onOff(fieldRead){
this.getField(fieldRead).readonly = event.target.isBoxChecked(0) ? readonly.false : readonly.true;}
Copy link to clipboard
Copied
No need to use readonly.false...etc false/true is enough, like this
? false : true;}