Skip to main content
June 7, 2017
Question

Un-check box, un-requre field

  • June 7, 2017
  • 1 reply
  • 262 views

I wrote the following JavaScript that runs when a customer "MouseUp" (clicks) a radio box. It requires them to fill out a field when the "yes" box is checked:

f="Explanation";

e="Yes: custom design";

tField=this.getField(f);

if(event.target.value==e){tField.required=true;}else{tField.required=false;}

"f" is the field in which the customer types their explanation, and "e" is the "yes" checkbox. The script is run through the "properties" of the "yes" check box.

My issue is that there is also a "no" box as part of the radio family. So, when the "no" box is clicked it "un-clicks" the "yes" box. Unfortunately, this does not "un-require" the explanation field. Can someone suggest an edit to my JavaScript to make this happen?

(I apologize if my explanations are poorly worded. I am very new to JavaScript)

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 1, 2017

You can reverse the logic of the last line, like this:

if (event.target.value!=e){tField.required=false;}else{tField.required=true;}