select元素中的选项取决于另一个select元素的选定值 [英] Options in a select element depend on selected value of another select element

查看:135
本文介绍了select元素中的选项取决于另一个select元素的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我在php中创建一个接口,用于从mysql数据库中提取数据。我开始做的是HTML,这是我所熟知的。 php是一个不同的故事。


我已经达到了一个点,我正在查看我创建的各种表单,并考虑一些下拉框以及用户将如何能够相应地输入数据。我在整个数据库中有很多独立的表。这些表的目的是向下拉框提供数据,以便用户可以选择所需的数据。例如:

Hello all. I am making an interface in php that will draw data from a mysql database. What I have started doing is the html, this is what I know well. php is a different story though.

I have reached a point where I am looking at the various forms I have created and thinking about some of the drop down boxes and how the user will be able to enter the data accordingly. I have throughout the database a lot of independant tables. The purpose of these tables is to provide data to a drop down box so the user can choose the desired data. For example:

展开 | 选择 | Wrap | 行号

推荐答案

更改了帖子标题以更好地描述问题(你知道标题包含诸如''help with'之类的短语的线程实际上得到了FEWER响应吗?)。


Heya,fjm。


如果我理解你在说什么,当用户从第一个下拉框中选择一个值时,你希望第二个下拉框的值根据所选值的变化而改变。这是正确的吗?


有几种方法可以做到这一点。您可以通过PHP重新加载页面并处理所有内容,或者您​​可以使用AJAX调用并使用JavaScript处理显示。


Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as ''help with'' actually get FEWER responses?).

Heya, fjm.

If I understand what you''re saying, when the User selects a value from the first drop down box, you want the values of the second drop down box to change depending on what that selected value is. Is this correct?

There are a couple of ways of doing this. You can reload the page and handle everything via PHP, or you can use an AJAX call and take care of the display using JavaScript.



更改主题标题以更好地描述问题(您是否知道标题包含诸如''help with'之类的短语的线程实际上得到了FEWER响应?)。
Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as ''help with'' actually get FEWER responses?).



感谢您对我的帖子进行标题的建议。我将在下次记住这一点。 :)

Thanks for the advice on titleing my post. I will keep that in mind for the next time. :)


如果我理解你在说什么,当用户从第一个下拉框中选择一个值时,你想要的值是第二个下拉框根据所选值的变化而变化。它是否正确?
If I understand what you''re saying, when the User selects a value from the first drop down box, you want the values of the second drop down box to change depending on what that selected value is. Is this correct?



是的,你是对的。我需要一组依赖的下拉框。我用谷歌搜索过,空手而归。我遇到了很多帖子,人们试图做同样的事情,但没有人成功。 (至少我还没找到一个)很多asp的东西,但不是php。

Yes, you are correct. I need a set of dependant drop down boxes. I have googled this and have came up empty-handed. I have run across a lot of posts where people are trying to do the same thing but nobody has been successful. (At least I haven''t found one yet) Lots of stuff for asp but not for php.


有几种方法可以做这个。您可以通过PHP重新加载页面并处理所有内容,或者您​​可以使用AJAX调用并使用JavaScript处理显示。
There are a couple of ways of doing this. You can reload the page and handle everything via PHP, or you can use an AJAX call and take care of the display using JavaScript.



嗯,我已经研究过ajax,对我来说这是不可能的。我绝对没有javascript知识,而且我遇到的教程并不适合胆小的人。 tutorails还假设你已经用js编程多年了。我真的无法理解它。


php虽然不同。如果可能的话我宁愿使用php。是否有可以指向我的教程或片段?

Well, I have looked into ajax and it is out of the question for me. I have absolutely no javascript knowledge and the tutorials I have come across are not for the faint at heart. The tutorails also assume you have been programming in js for years. I really couldn''t grasp any of it.

php is different though. I would rather use php if at all possible. Is there a tutorial or a snippet you can point me to?


顺便说一句,由于大多数语言从左到右阅读,它可能会使如果区位于左侧且扇区位于右侧而不是相反,则对您的用户更有意义。]
As an aside, since most languages read left-to-right, it might make more sense for your Users if ''district'' were on the left and ''sector'' were on the right instead of the other way around.]



是,你的权利,我只是重新创建,以显示我的HTML。它实际上是一个堆叠在另一个之上。像这样:




行业


是否有更简单的方法可以做到这一点。也许甚至没有使用javascript或ajax?>


感谢您的帮助!

Yes, your right, I just recreated that to show my html. It is actually stacked one on top of the other. Like so:

District
Sector

Is there maybe an easier way to do this. Maybe without even using javascript or ajax?>

Thanks for your help!



是否有更简单的方法可以做到这一点。也许甚至没有使用javascript或ajax?
Is there maybe an easier way to do this. Maybe without even using javascript or ajax?



是的...你可以使用PHP生成一个javascript ...我认为javascript是必不可少的''因为你正在处理表单..


生病了回来.. ^ ___ ^

yes... you can use PHP to generate a javascript... i think javascript is essential ''cause you''re dealing with forms..

ill be back with a script.. ^___^


这篇关于select元素中的选项取决于另一个select元素的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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