使用PHP依赖下拉? [英] Dependant dropdowns with PHP?

查看:91
本文介绍了使用PHP依赖下拉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里获得了胜利者...


我需要一个解决方案,它将使用单个html选择和两个取决于所选值的输入字段。


此下拉列表将包含3个值。如果选择了某个值,我需要输入两个输入框。如果选择了其他两个值中的任何一个,那么就不应该添加额外的输入框。


这听起来像AJAX的工作我肯定但是我不知道关于AJAX。


我现在拥有的是带有js onchange事件的select标签,当用户从选择框中选择值时会触发该事件。使用php,我测试POST var,如果它是我需要额外输入框的值,我回应它们。在我需要提交页面之前,这一切都很好。


理论上,我使用onchange设置页面,然后在完成后提交整个页面。这就是我遇到问题的原因,因为这样做,我需要嵌套表单标签,我不认为这是正确的。


是否有人有代码示例他们可以和我分享,还是指点我需要去的方向?


谢谢,


Frank

I got a winner here..

I need a solution that will use a single html select and two input fields that depend on the value selected.

This dropdown will have 3 values. If a certain values is selected, I need two input boxes to appear. If either of the other two values are selected, then no additional input boxes should be added.

This sounds like a job for AJAX i''m sure but I haven''t a clue about AJAX.

What I have now is a select tag with a js onchange event that fires when the user selects the value from the select box. With php, I test for the POST var and if it is the value where I need the additional input boxes, I echo them. This is all well and good until I need to submit the page.

In theory, I setup the page using the onchange and then submit the entire page after it has been completed. This is where I have my problem because to do it like this, I would need to nest form tags and I don''t think this is correct.

Does someone have a code sample they could share with me or point me in the direction that I need to go?

Thanks,

Frank

推荐答案

两个值都来自数据库吗?在这种情况下,AJAX将是最好的方法。
Will both values be coming from the database? In which case AJAX would be the best approach.



两个值都来自数据库吗?在这种情况下,AJAX将是最好的方法。
Will both values be coming from the database? In which case AJAX would be the best approach.



嗨r035198x,


不,实际上,这些都不需要db访问来填充。我正在使用硬编码值填充选择框。将有3个选项值(1,2和3)。


当用户选择选项#2时,我需要向用户显示另外两个选项。只是为了澄清,当选择选项#2时,它仅作为触发器,以便显示其他选择。 (并且在提交表单时也使用

Hi r035198x,

No, actually, none of these will require db access to populate. I am populating the select box with hard coded values. There will be 3 option values (1,2, and 3).

When the user selects option #2 I need to show another two selects to the user. Just for clarification, when option #2 is selected it is only acting as a trigger so to speak to show the additional selects. (And also using the value for


_POST的值。


换句话说,如果未选择选项#2,我不想看到额外的两个选择。当然,如果是,请显示它们。


当整个表单完成时,所有选择的值,无论是需要提交一个或全部三个。


我不知道如何处理这个....


谢谢你帮助r035198x!


Frank
_POST when the form is submitted.

In other words, if option #2 is NOT selected, I don''t want to see the additional two selects. Of course, if it is, show them.

When the entire form is completed, the values from all of the selects, whether a single select or all three need to be submitted.

I am not sure how to handle this....

Thanks for the help r035198x!

Frank


这篇关于使用PHP依赖下拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆