jasonmklug jasonmklug - 2 years ago 83
HTML Question

How can I add an "Other" text input to a set of radio buttons in an HTML form?

I'm trying to create a form with a write-in "other" option as the last radio button. I've tried variants of the following with no success:

<label><input type="radio" name="candidate" value="option1">First Option</label>
<label><input type="radio" name="candidate" value="option2">Second Option</label>
<label><input type="radio" name="candidate" value="other">OTHER</label><input type="text" name="other" value="Write In" />

Is it possible to have a radio button with a text input that passes its value to that radio button on submit without using javascript?

Answer Source

If 'Other' is selected, you would want to submit only the value in the text field, it does not make sense to feed that into the radio and pass that to the server. You could give the value of the 'Other' radio the empty string, e.g.:

<label><input type="radio" name="candidate" value="">OTHER</label>

And on the server if no value is present in "candidate" look to "other".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download