HTML Form problem, choose an existing problem or add a new one
I am developing a form for a PHP application and I need to have a form where the user can either select开发者_如何学Go an option from a drop down menu or add a new option via the same form?
What type of form input is this called? Is this even possible?
Thanks
A select dropdown with an "Other" option, and where other is selected allow and/or require them to enter a value into a standard text input field. You'll need the two form elements, can't be done with one.
I don't think there is a specific type of input for this.
You would have to create a separate select box and input text box, then write some PHP to do server-side checking to use the input box if the user doesn't select an option from the drop-down.
I believe that what you would need to do is have a selection-menu or a series of checkboxes for the pre-defined answers, and then have an "other" option. If the user selects "other", then use some DHTML to pop-up a TextField.
Then in your PHP script, check if the "other" option was picked. If it was, just use the data from the TextField as your data for that particular form piece.
in html 5 you can use a text box with an associated datalist...
there's javascript out there to make it happen in crap browsers too,
Well a drop down menu is an html <select>
element
Like so:
<select>
<option>Option1</option>
<option>Option2</option>
</select>
Then if you want to add an option you can have a separate textbox where the user can type in their value and then use PHP to insert a new <option>
when the form is submitted.
I believe this may work out good for you. It's a JQuery plugin for a combobox that has various customization, among wich the ability to create on-the-fly a value and store it inside the dropdown list. Check the demos to see it in action. I never tried it but it looks really good.
jquery-jec
精彩评论