<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: Dependent combo boxes</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/dependent-combo-boxes</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/dependent-combo-boxes/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>sebastiancb on Dependent combo boxes</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/dependent-combo-boxes#p27456</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/dependent-combo-boxes#p27456</guid>
        	        	<description><![CDATA[<p>Hello, please what I need is to implement two dependent combobox in the jqgrid, but I have no idea, I have seen examples but I can`t get they work.</p>
<p>The first combobox loads the countries and depending of the country the second combobox loads the cities.</p>
</p>
<p>The source code:</p>
<p><strong>index.php</strong></p>
</p>
<p>&#60;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&#62;<br />&#60;html xmlns="http://www.w3.org/1999/xhtml"&#62;<br />&#60;head&#62;<br />&#60;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&#62;<br />&#60;title&#62;Ejemplo&#60;/title&#62;<br />&#60;script type="text/javascript" src="jquery.js"&#62;&#60;/script&#62;<br />&#60;script type="text/javascript" src="jquery-ui.js"&#62;&#60;/script&#62;<br />&#60;script type="text/javascript" src="grid.locale-es.js"&#62;&#60;/script&#62;<br />&#60;script type="text/javascript" src="jquery.jqGrid.min.js"&#62;&#60;/script&#62;<br />&#60;link href="jquery-ui.css" rel="stylesheet" type="text/css" /&#62;<br />&#60;link href="ui.jqgrid.css" rel="stylesheet" type="text/css" /&#62;</p>
<p>&#60;script type="text/javascript"&#62;<br />$(document).ready(function(){ <br />//--------------------------------------<br />function load_countries(){<br />var countries;<br />&#160;&#160; &#160;$.ajax({<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; url: &#39;load_countries.php&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; type: &#39;get&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; async: false,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; success: function(data){<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;countries=data;&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; }<br />&#160;&#160; &#160;&#160;&#160; &#160;});<br />&#160;&#160; &#160;return countries;<br />}<br />//--------------------------------------<br />function load_cities(id){<br />var cities;<br />&#160;&#160; &#160;$.ajax({<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; url: &#39;load_cities.php?id_country=&#39;+id,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; type: &#39;get&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; async: false,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; success: function(data){<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;cities=data;&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; }<br />&#160;&#160; &#160;&#160;&#160; &#160;});<br />&#160;&#160; &#160;return cities;<br />}</p>
<p>//--------------------------------------<br />$("#list3").jqGrid({ url:&#39;list.php&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;datatype: "xml", <br />&#160;&#160; &#160;&#160;&#160; &#160;colNames:[&#39;Id&#39;,&#39;name&#39;,&#39;country&#39;,&#39;city&#39;], <br />&#160;&#160; &#160;&#160;&#160; &#160;colModel:[<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;idp&#39;,index:&#39;idp&#39;, width:100,sortable:true,editable:true}, <br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;name&#39;,index:&#39;name&#39;, width:100,sortable:false,editable:true,sortable:true}, <br />&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;namect&#39;,index:&#39;namect&#39;, width:150,sortable:false,editable:true,sortable:true,edittype:&#39;select&#39;,editoptions:{value:load_countries(),dataEvents:[{<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; type:&#39;change&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fn:function(e){id_country=$(e.target).val();//get id country to load the cities in the following combobox with the function load_cities <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160; //How to update the combobox namecy depending of the country<br />&#160;&#160; &#160;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }]}},<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;namecy&#39;,index:&#39;namecy&#39;, width:150,sortable:false,editable:true,sortable:true,edittype:&#39;select&#39;}],<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; recreateForm:true,<br />&#160;&#160; &#160;&#160;&#160; &#160;rowNum:10,<br />&#160;&#160; &#160;&#160;&#160; &#160;rowList:[10,20,30],<br />&#160;&#160; &#160;&#160;&#160; &#160;pager: &#39;#pager3&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;sortname: &#39;idp&#39;, <br />&#160;&#160; &#160;&#160;&#160; &#160;viewrecords: true, <br />&#160;&#160; &#160;&#160;&#160; &#160;sortorder: "asc",<br />&#160;&#160; &#160;&#160;&#160; &#160;xmlReader: {root: "rows",<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; repeatitems : true,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; id: "[id]"&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; },<br />&#160;&#160; &#160;&#160;&#160; &#160;caption: "Estudiantes",<br />&#160;&#160; &#160;&#160;&#160; &#160;height:&#39;100%&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;editurl:"edit.php"<br />});</p>
<p>//--------------------------------------<br />$("#list3").jqGrid(&#39;navGrid&#39;,&#39;#pager3&#39;,{edit:true,add:true,del:true,search:true});<br />//**********************************************************************************<br />});<br />&#60;/script&#62;<br />&#60;/head&#62;<br />&#60;body&#62;<br />&#160;&#60;table id="list3"&#62;&#60;/table&#62;<br />&#160;&#60;div id="pager3"&#62;&#60;/div&#62; <br />&#60;/body&#62;<br />&#60;/html&#62;</p>
<p><strong><br /></strong></p>
<p><strong>load_countries.php</strong></p>
<p>&#60;?php<br />$bd = mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());<br />mysql_select_db("depselect") or die("Error conecting to db.");<br />$id_country=$_GET[&#39;id_country&#39;];<br />$sql="select id,namecy from cities where idc=$id_country";<br />$rs = mysql_query($sql);<br />$cities="";<br />while ($reg=mysql_fetch_array($rs)) {<br />$cities=$cities.$reg[&#39;id&#39;].":".$reg[&#39;namecy&#39;].";";<br />}</p>
<p>$cities=substr($cities,0,strlen($cities)-1);<br />echo utf8_encode($cities);<br />?&#62;</p>
<p><strong>load_cities.php</strong></p>
<p>&#60;?php<br />$bd = mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());<br />mysql_select_db("depselect") or die("Error conecting to db.");<br />$id_country=$_GET[&#39;id_country&#39;];<br />$sql="select id,namecy from cities where idc=$id_country";<br />$rs = mysql_query($sql);<br />$cities="";<br />while ($reg=mysql_fetch_array($rs)) {<br />$cities=$cities.$reg[&#39;id&#39;].":".$reg[&#39;namecy&#39;].";";<br />}</p>
<p>$cities=substr($cities,0,strlen($cities)-1);<br />echo utf8_encode($cities);<br />?&#62;</p>
]]></description>
        	        	<pubDate>Mon, 01 Oct 2012 22:36:30 +0300</pubDate>
        </item>
</channel>
</rss>