Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Dependent combo boxes
01/10/2012
22:36
Avatar
sebastiancb
COlombia
Member
Members
Forum Posts: 23
Member Since:
05/09/2011
sp_UserOfflineSmall Offline

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.

The first combobox loads the countries and depending of the country the second combobox loads the cities.

The source code:

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ejemplo</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript" src="grid.locale-es.js"></script>
<script type="text/javascript" src="jquery.jqGrid.min.js"></script>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="ui.jqgrid.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
$(document).ready(function(){
//--------------------------------------
function load_countries(){
var countries;
    $.ajax({
           url: 'load_countries.php',
           type: 'get',
           async: false,
           success: function(data){
            countries=data;        
           }
        });
    return countries;
}
//--------------------------------------
function load_cities(id){
var cities;
    $.ajax({
           url: 'load_cities.php?id_country='+id,
           type: 'get',
           async: false,
           success: function(data){
            cities=data;        
           }
        });
    return cities;
}

//--------------------------------------
$("#list3").jqGrid({ url:'list.php',
        datatype: "xml",
        colNames:['Id','name','country','city'],
        colModel:[
                {name:'idp',index:'idp', width:100,sortable:true,editable:true},
            {name:'name',index:'name', width:100,sortable:false,editable:true,sortable:true},
        {name:'namect',index:'namect', width:150,sortable:false,editable:true,sortable:true,edittype:'select',editoptions:{value:load_countries(),dataEvents:[{
               type:'change',
               fn:function(e){id_country=$(e.target).val();//get id country to load the cities in the following combobox with the function load_cities
                  //How to update the combobox namecy depending of the country
    
                             }
               }]}},
                {name:'namecy',index:'namecy', width:150,sortable:false,editable:true,sortable:true,edittype:'select'}],
                recreateForm:true,
        rowNum:10,
        rowList:[10,20,30],
        pager: '#pager3',
        sortname: 'idp',
        viewrecords: true,
        sortorder: "asc",
        xmlReader: {root: "rows",
                            repeatitems : true,
                           id: "[id]"                           
                          },
        caption: "Estudiantes",
        height:'100%',
        editurl:"edit.php"
});

//--------------------------------------
$("#list3").jqGrid('navGrid','#pager3',{edit:true,add:true,del:true,search:true});
//**********************************************************************************
});
</script>
</head>
<body>
 <table id="list3"></table>
 <div id="pager3"></div>
</body>
</html>


load_countries.php

<?php
$bd = mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());
mysql_select_db("depselect") or die("Error conecting to db.");
$id_country=$_GET['id_country'];
$sql="select id,namecy from cities where idc=$id_country";
$rs = mysql_query($sql);
$cities="";
while ($reg=mysql_fetch_array($rs)) {
$cities=$cities.$reg['id'].":".$reg['namecy'].";";
}

$cities=substr($cities,0,strlen($cities)-1);
echo utf8_encode($cities);
?>

load_cities.php

<?php
$bd = mysql_connect("localhost","root","") or die("Connection Error: " . mysql_error());
mysql_select_db("depselect") or die("Error conecting to db.");
$id_country=$_GET['id_country'];
$sql="select id,namecy from cities where idc=$id_country";
$rs = mysql_query($sql);
$cities="";
while ($reg=mysql_fetch_array($rs)) {
$cities=$cities.$reg['id'].":".$reg['namecy'].";";
}

$cities=substr($cities,0,strlen($cities)-1);
echo utf8_encode($cities);
?>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
46 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information