How can I make a switch for "Other - please specify?"

I am creating an HTML form with some switch options. I would like to have one option: "Other - please indicate" and allow the user to enter text.

Two questions:

1) How can I create a "hybrid" input type radio/text ?

2) On the back of PHP, if the input has the same name attribute as the radio inputs, will the user input be part of the same array?

+6
html php radio-button forms
source share
3 answers

# 1: in the "other:" field, add <input type="text" ...> with the style: none and only display it when the user selects the "other:" radio field.

However, I'm not entirely sure that No. 2 will work. You will get rboption=other from the AND rboption=some%20text from the text box. One will usually overwrite the other, but he is not sure what (read: depends on the position on the page, browser and moon phase).
Of course, change the name of the field and process it only when rboption == 'other' (as rboption == 'other' said)

+6
source share

Why not just add another name attribute to the input and confirm it only if another switch is selected?

+8
source share

Here is how I did it:

 <input type="radio" name="phone" value="313-375-2151">Taylor <br> <input type="radio" name="phone" value="555-444-1234">OverheadHts <br> <input type="radio" name="phone" value="555-333-1234">Smith Ctr <br> <input type="radio" name="phone" value="444-344-1234">Mainsville<br> <input type="radio" name="phone" value="other">Other: <input type="text" name="phone-other" size="14"> 

And then when you process the form:

 $phone = mysql_real_escape_string($_POST['phone']); if ($phone =='other'){ $phone = mysql_real_escape_string($_POST['phone-other']); } 

and etc.

+8
source share

All Articles