HTML 表单问题,选择现有问题或添加新问题
我正在为 PHP 应用程序开发一个表单,我需要一个表单,用户可以从下拉菜单中选择一个选项,或者通过同一表单添加一个新选项?
这称为什么类型的表单输入?这可能吗?
谢谢
I am developing a form for a PHP application and I need to have a form where the user can either select 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
带有“其他”选项的选择下拉菜单,以及选择其他的位置允许和/或要求他们在标准文本输入字段中输入值。您需要两个表单元素,但仅用一个元素是无法完成的。
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.
我认为没有特定类型的输入。
您必须创建一个单独的选择框和输入文本框,然后编写一些 PHP 来进行服务器端检查,以便在用户未从下拉列表中选择选项时使用输入框。
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.
我相信您需要做的是有一个选择菜单或一系列用于预定义答案的复选框,然后有一个“其他”选项。如果用户选择“其他”,则使用一些 DHTML 弹出一个 TextField。
然后在您的 PHP 脚本中,检查是否选择了“其他”选项。如果是,只需使用 TextField 中的数据作为该特定表单的数据。
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.
在 html 5 中,您可以使用带有关联数据列表的文本框...
也有 javascript 可以使其在垃圾浏览器中发生,
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,
下拉菜单是一个 html
如下所示:
然后,如果您想添加一个选项,您可以有一个单独的文本框,用户可以在其中输入其值,然后使用 PHP 来添加选项。提交表单时插入新的
。
Well a drop down menu is an html
<select>
elementLike so:
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.我相信这可能对你有好处。
它是一个用于组合框的 JQuery 插件,具有各种自定义功能,其中能够即时创建值并将其存储在下拉列表中。检查演示以查看其实际效果。我从未尝试过,但看起来确实不错。
jquery-jec
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