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 });});
BackgroundCodePHP:
<? 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]) ;}}