Reputation: 215
I am creating a questionnaire with PHP and jQuery. I have the following radio list:
Question A:
O Answer X
O Answer Y
O Answer Z
O Other [input text field]
Now, when people directly select the input text field, I want the radiobutton of "Other" automatically be selected.
in HTML it looks like this:
Answer X
Answer Y
Answer Z
Other
I have this in jQuery:
<script type="text/javascript">
$("input.customInput").focus(function ()
{
$('input:radio[name='question[A]']:checked').val() == 'Other');
});
</script>
Upvotes: 1
Views: 2686
Reputation: 33
I found the code that apply for checkbox. So modify this one for the radio button. Hope this will help you
<input type="radio" name="mypet" id="radio_yes" value="Yes">
<input type="radio" name="mypet" id="radio_no" value="No">
<input type="text" name="boxname" id="boxname" onFocus="this.form.radio_yes.checked=true">
Upvotes: 0
Reputation: 4337
It's possible to do without JS:
<input type="radio" id="radioButton" />
<label for="radioButton">
Other<input type="text" />
</label>
demo: http://jsfiddle.net/vV4P9/
Upvotes: 4
Reputation: 597
This can be done with HTML by placing your text input
inside the label
for the "Other" radio button.
Upvotes: 0