I am using the Jquery Select2 script http://ivaynberg.imtqy.com/select2/#ajax .
I have two dropdownlist - First choice for regions - Second Choose for cities
Question: How to transfer a variable from the first choice (static content) to the second choice (dynamic Ajax content)
With the second selection, I would like to download only data for one selected region. At the beginning, the second selection is disabled. When the user selects a region, a second selection should be activated.
HTML code
<div class="control-group"><label class="control-label">Region</label> <div class="controls"> <select id="region" name="region"> <option value="">Select region</option> <option value="1">Region 1</option> <option value="2">Region 2</option> </select> </div> </div> <input type="hidden" id="city" name="city" class="input-xlarge" data-placeholder="Choose An Option.." />
JavaScript:
<script type="text/javascript"> $(document).ready(function() { var $region = $('#region'); var $city = $('#city'); $region.change(function() { if ($region.val() == '') { $city.attr('disabled', 'disabled').val(''); $("#city").select2("enable", false); } else { $("#city").select2("enable", true); } }).trigger('change'); }); $('#city').select2({ minimumInputLength: 2, ajax: { url: "index.php?modul=data®=2", contentType: 'application/json; charset=utf-8', dataType: 'json', data: function (term, page) { return { q: term, }; }, results: function (data, page) { return { results: data }; } } }); </script>
Do I need a pass value from the first selection to the variable "reg" Index.php? Modul = data & p = 2 Index.php? Modul = data & p = 2 & d = CITYNAME
Darek source share