Cascade case of province, city, and county

Source: Internet
Author: User

Javascript ::

$ (Function () {var province = $ ('# province '). comboBox ({valuefield: 'areaid ', textfield: 'name', Editable: false, URL: 'cascade-data. php', onchange: function (newvalue, oldvalue) {$. get ('cascade-data. php', {parentid: newvalue}, function (data) {city. comboBox ("clear "). comboBox ('loaddata', data); County. comboBox ("clear")}, 'json') ;}}); var city =$ ('# City '). comboBox ({valuefield: 'areaid ', textfield: 'name', Editable: false, onchange: function (newvalue, oldvalue) {$. get ('cascade-data. php', {parentid: newvalue}, function (data) {County. comboBox ("clear "). comboBox ('loaddata', data) ;}, 'json') ;}}); var County =$ ('# County '). comboBox ({valuefield: 'areaid ', textfield: 'name', Editable: false });});





<? PHP $ parentid = isset ($ _ Get ['parentid'])? $ _ Get ['parentid']: 0; $ mysql = new saemysql (); $ SQL = "select * From 'region' where parentid = $ parentid order by vieworder "; $ DATA = $ mysql-> getdata ($ SQL); echo json_encode ($ data );


As someone mentioned, the first one is selected for initialization:

You can add the onloadsuccess: onloadsuccess to ComboBox. The content of the onloadsuccess method is as follows:

Function onloadsuccess () {var target = $ (this); var DATA = target. comboBox ("getdata"); var Options = target. comboBox ("options"); If (Data & data. length> 0) {var FS = data [0]; target. comboBox ("setvalue", FS [options. valuefield]) ;}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.