Asked 8 years ago
10 Dec 2016
Views 1373
jqueryLearner

jqueryLearner posted

select2 js on change event

using

select2 - jQuery for selection boxes and using multiple selection
its region dropdown where i want to select more than region at a time.



used code ::


<script type="text/javascript">
$(".region").select2();
</script>

<select class="region" id="region" multiple="multiple">
  <option value="AL">Alabama</option>
    ...
  <option value="WY">Wyoming</option>
</select>


it working good
but now want to do some more action like .. on the selection of any region . i want to load some more divs from ajax .

so what i tried is


$(document).ready(function () {
  $("#region").parent().find("input").change(function(){
	alert($(this).val());// want to populate some more div based on the change .
 }) 
  $("#region").parent().find("input").click(function(){
        alert($(this).val());/
	// remove some thing // or add new div or any event
  });
 });


find("input") is giving me hidden input created by select2 . but on change event not giving value on change.

same as for click event. it not giving any alert.

i put alert for just demo purpose but i want to send ajax request to server to get more result on based on the selection.




Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00


var $eventSelect =$(".region").select2();
$(".region").on("change", function () { alert($(this).val())});
$(".region").on("click", function () { alert($(this).val())});


hope it help.

check more detail

Post Answer