2

I have a form with mainly all simple textboxes and I am using the required attribute for the fields that are required. However, I have a textarea that only needs to be required if the previous radio button is selected as "Yes", otherwise I don't want the textarea to be required. Here is the code for those 2 fields:

<input id="ElecWiFi" name="ElecWiFi" required type="radio" 
value="Yes" />
<textarea id="WiFiNeeds" cols="50" name="WiFiNeeds" rows="3" 
placeholder="Electricity or Wi-Fi Needs"></textarea>

How would I make the textarea required only if Yes was selected in ElecWiFi field? Thanks in advance for any help.

dr1054

dr1054
  • 89
  • 1
  • 4
  • 10

1 Answers1

1

add javascript to the click attribute like so

<input id="ElecWiFi" name="ElecWiFi" required type="radio" value="Yes" onclick="document.getElementById('WiFiNeeds').setAttribute('required', 'required')" />

Prasun Jajodia
  • 470
  • 3
  • 15