Skip to content

Instantly share code, notes, and snippets.

@temochka
Created January 22, 2012 17:47
Show Gist options
  • Save temochka/1657867 to your computer and use it in GitHub Desktop.
Save temochka/1657867 to your computer and use it in GitHub Desktop.
Continent/Country/City example for Stefan
<!DOCTYPE html>
<html>
<head>
<title>jquery-dependentSelect</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/temochka/jquery-dependentSelect/master/jquery.dependentSelect-0.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('select#single-local-data').dependentSelect({
isMultiple: false,
selects: [
{ model: "Continent" },
{ model: "Country" },
{ model: "City" }
],
dataSource:
{
'Continent': {
values: [
{ value: 1, text: "Asia" },
{ value: 2, text: "Europe" }
],
relatedTo: 'Country',
relations: {
1: [1,2,3],
2: [4,5]
}
},
'Country': {
values: [
{ value: 1, text: 'Japan' },
{ value: 2, text: 'China' },
{ value: 3, text: 'Spain' },
{ value: 4, text: 'India' },
{ value: 5, text: 'Czech Republic' },
],
relatedTo: 'City',
relations: {
1: [1],
2: [2],
3: [3,4],
4: [5],
5: [6]
}
},
'City': {
values: [
{ value: 1, text: 'Tokio' },
{ value: 2, text: "Pekin" },
{ value: 3, text: "Madrid" },
{ value: 4, text: "Barcelona" },
{ value: 5, text: "New Delhi" },
{ value: 6, text: "Prague" },
]
}
}
});
});
</script>
</head>
<body>
<form>
<select id="single-local-data"></select>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment