speedmax (owner)

Revisions

gist: 185196 Download_button fork
public
Public Clone URL: git://gist.github.com/185196.git
Embed All Files: show embed
dependent select box (example in jquery).html #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<select id="country">
  <optoin>Australia</option>
  <option>China</option>
</select>
 
<select id="city">
</select>
 
 
<script>
var cities = {
  "China": ["Hong Kong", "Beijing"],
  "Australia", ["Sydney", "Melbourn"]
}
 
$('#country').change(function(){
  $('#city').html('')
  
  $.each(cities[this.value], function(city) {
     $('#city').append('<option>' + city +'</optoin>')
  })
})
</script>
 
 
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<select id="country">
  <optoin>Australia</option>
  <option>China</option>
</select>
 
<select id="city">
</select>
 
 
<script>
var cities = {
  "China": ["Hong Kong", "Beijing"],
  "Australia", ["Sydney", "Melbourn"]
}
 
$('country').observe('change', function(){
  $('city').setHtml('');
  
  cities[this.value].each(function(city) {
     $('city').append(new Element('option', text: city))
  })
})
</script>