Skip to main content
alessiab66245732
Participant
June 13, 2018
Question

Show/Hide fields based on checkbox that doesn't work

  • June 13, 2018
  • 1 reply
  • 3531 views

Hello everyone. Since I don't know anything of javascript  and even if I checked other posts in this community, my field doesn't disappear.

So I have a checkbox called "another country" when the user selects this checkbox a dropdown menu should appear, called "select a location" with a list of other countries.

At the moment this is not working and I see both the checkbox and the field.

This is the script I've added:

// Show/hide select a location text fields

var nHide = another.target.isBoxChecked(0)?display.visible:display.hidden;

this.getField("Select a location").display = nHide;

// Show/hide select a location text field label overlays

this.getField("Overlay_1").display = event.target.value == "Off"? display.visible: display.hidden;

Can someone tell me what's wrong?

Thanks,

Alessia

This topic has been closed for replies.

1 reply

Inspiring
June 13, 2018

how about:

if (event.target.isBoxChecked(0)){

   this.getField("Select a location").display = display.visible

}

else{

   this.getField("Select a location").display = display.hidden

}

alessiab66245732
Participant
June 14, 2018

Hello,

thanks it worked But I had to change it in this way, with 1 instead of 0.

if (event.target.isBoxChecked(1)){

   this.getField("Select a location").display = display.visible

}

else{

   this.getField("Select a location").display = display.hidden

}

I have another issue now, that when I select the checkbox "another country" it appears the dropdown menu with the list, but unfortunately if I press the other checkbox the dropdown menu doesn't disappear, it stays there.

I would like this dropdown menu to disappear when the customer clicks back on the other checkbox.. do you have any suggestion?

Inspiring
June 15, 2018

Problably your fields all share the same name.

isBoxChecked() has a parameter that represents:

"The 0-based index of an individual radio button or check box widget for this field. The index is determined by the order in which the individual widgets of this field were created (and is unaffected by tab-order).

Every entry in the Fields panel has a suffix giving this index, for example, MyField #0."

So you need to change the number to reflect the targeted box

alessiab66245732  a écrit

I have another issue now, that when I select the checkbox "another country" it appears the dropdown menu with the list, but unfortunately if I press the other checkbox the dropdown menu doesn't disappear, it stays there.

I would like this dropdown menu to disappear when the customer clicks back on the other checkbox.. do you have any suggestion?

What "Other checkbox" are you refering to?