如何创建可扩展表单
我正在尝试收集有关高中体育组织的信息以及该体育项目主教练的姓名。由于不同学校的体育项目数量不同,因此形式需要自行扩展,直至满足体育项目数量。它应该看起来像这样:
Sport____________ 主教练_____________
[+]
如果点击加号按钮,下面应该出现另一个相同的形式 它。它应该看起来像这样:
Sport____________ 主教练_____________
运动____________主教练< /em>_____________
[+]
等等等等。有谁知道这是如何做到的?提前致谢。
PS:我使用的是 Dreamweaver 和 MAMP
I am trying to collect information on sports organizations available at a high school and the name of the head coach of that sport. Because different schools have different numbers of sports, the form will need to expand itself until the number of sports is met. It should look like this:
Sport____________Head Coach_____________
[+]
If the plus sign button is hit, another identical form should appear below it. It should look like this:
Sport____________Head Coach_____________
Sport____________Head Coach_____________
[+]
and so on and so on. Does anyone have any idea how this is done? Thanks in advance.
PS: I am using dreamweaver and MAMP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个由两部分组成的解决方案。上述问题的主要答案(向表单添加额外的字段)是一段相当简单的 JavaScript,您可以在这里找到一个这样的示例:
http://www.randomsnippets.com/2008/02/21/how-to-dynamically-add-form-elements-via-javascript/
第二部分涉及你做什么提交后的表单数据。如果您只是将表单发送到电子邮件,那么循环提交数组的任何脚本都会选择额外的字段。
如果您将数据存储到数据库中,则会变得稍微困难一些,因为您需要能够将数据写入一篇文章的两个表中。 Dreamweaver 无法处理此问题,因此您可能需要在编写解决方案之前更好地使用 PHP。
It's a two part solution. The primary answer to the above (add extra fields to a form) is a fairly simple bit of javascript of which you can find one such example here:
http://www.randomsnippets.com/2008/02/21/how-to-dynamically-add-form-elements-via-javascript/
The second part involves what you do with the form data after submission. If you are merely going form to email then any script that loops through the array of submissions will pick up the extra fields.
If you are storing the data to a database, it gets slightly harder as you need to be able to write data to two tables off of one post. Dreamweaver is not equipped to handle this so you probably will need to get better with PHP before coding the solution.