国家,州,城市选择 [英] country,state,city selection

查看:106
本文介绍了国家,州,城市选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们...


在我的php页面3下拉列表框中有..即国家,州,城市..


如果选择了国家,则在onchange函数中。必须在状态下拉列表框中填充相应的状态..同样,如果选择特定状态,则必须在第3个列表框中填充相应的城市..


你可以帮我吗??


谢谢...

解决方案

听起来你需要使用Javascript AJAX

onclick或onchange事件在第一个选择框(国家)将触发第二个Dropbox的填充(统计数据......)......
请阅读此处以开始使用


AJAX对于像这样的任务。


如果你知道可能的国家,州,城市等,将它存储在一个javascript数组中会更有效率,我会期待的

好的,这是另一个解决方案。如何将每个国家/地区的2个字母代码填充到PHP关联数组中,然后在循环中使用它来生成select语句所需的代码。只是一个想法,看看这是一个PHP论坛。 :)


或者,您可以抓住成品这里


您可以为状态执行相同操作,实际上这里是我上面提到的一个例子,但是有一个非关联数组。


通过一些小的更改,您可以生成一个生成相同内容的国家/地区选择框。至于城市选择,考虑到每个国家的城市数量,这可能包含很多繁琐的编码。这个城市可能会更好地作为用户进入的领域。


问候,


杰夫


hi friends...

in my php page 3 dropdownlist boxes are there.. ie country,state,city..

if country is selected, in onchange function.. corresponding states has to be populated in state dropdownlist box.. likewise if particular state is selected corresponding city has to be populated in 3rd list box..

can u help me??

thank you...

解决方案

sounds like you need to use Javascript AJAX
onclick or onchange event on the first select box (countrys) will trigger the populate of the second dropbox (stats...) ...
read here to get you started


AJAX is pointless for a task like this.

If you know ever possible country, state, city, etc., it''d be more efficient to store it in a javascript array, I''d expect.


Ok, so here is another solution. How about populating each country and its 2 letter code into an PHP associative array and then using it in a loop to produce the code needed for the select statement. Just an idea, seeing as how this is a PHP forum. :)

Or, you can just grab the finished product here.

You can do the same for states, in fact here is an example of what I was referring to above, but with a non-associative array.

With a few minor changes, you can produce a country select box that produces the same thing. As for the city select, that is quite a bit more entailed and would probably consist of a lot of tedious coding considering the number of cities in each country. The city might be better served as a user entered field.

Regards,

Jeff


这篇关于国家,州,城市选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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