Forum Moderators: open

Message Too Old, No Replies

Forms: choice of radio button or text answer

but not both!

         

karen_pope

3:38 pm on Apr 4, 2002 (gmt 0)



If you had a question that had a number of radio buttons and an option of a text box for the user to enter their own choice all in the same question - how would you make sure that only the text box or a radio option was selected and not both.

My code at the moment is:

<p><input type="radio" name="Q1" value="a">a
<br><input type="radio" name="Q1" value="b">b
<br><input type="radio" name="Q1" value="c">c
<br>Other (please state) <input type="text" name="Q1">

Please help!
Thanx!
Karen

txbakers

3:43 pm on Apr 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again you're going to need javascript to accomplish this.

First, don't name the radios the same as the textbox. It will confuse the form handler.

In your submit, you would validate the form before submitting. If a user checked a box and filled in the text box I would warn them with an "alert".

If not, then assign either of the values (radio or text) to a hidden field in the form.

It gets complicated after a while.