Is there a way to make a text prompt required only when a certain radio button is selected

Hi everyone, I am working on the Survey Form certification project and I was curious if there is a way to make a text input required only if a specific radio button is selected. I know this is not part of the challenge but I am just curious. Many times a radio button labeled as “Other” has a text box to enter what that other item is. I want to make this text box required only if this button is selected.

I tried nesting the text input within the associated radio button and added the required attribute to the text field. But this just makes it required regardless of the radio button selected. :man_shrugging:

<label><input type="radio" value="other" name="offense-defense" class="inline" /> Other<label>If other please specify: <input type="text" name="other" placeholder="e.g. goalkeeping, pitching, etc." required /></label></label>

You can. With plain JS you would use Event Listeners to update the page when the radio button is selected.

Oh ok so there’s no way to do it with just html5 then?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.