PanczerTank
PanczerTank

Reputation: 1130

How to combine an radio input with a text input

I'm trying to build a combined radio / text input for an "other" field in a form.

<input id="artist" type="radio" name="artist" value="Other">
<input id="other-artist" type="text" name="other_artist" placeholder="Other Artist"/>

I can't figure out how to click inside the text input and have the radio selected. I tried wrapping the text input in a label but that did not work.

Upvotes: 0

Views: 1153

Answers (1)

Morganster
Morganster

Reputation: 311

you can add a onclick event to de input and check the radio like this.

<input id="artist" type="radio" name="artist" value="Other">

<input id="other-artist" type="text" name="other_artist"placeholder="Other Artist" 
onClick="selectRadio()" />

and the js

selectRadio = () => {
     var radio = document.getElementById("artist");
     radio.checked = true;
}

example

hope this help.

Upvotes: 2

Related Questions