Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect change of select list using Jquery

Is there a way to detect when the value of a select list is set to empty by a javasscript and not by the user? It seems that the change-event only triggers by mouse or keyboard.

And is there a way to detect when the number of options in a select list changes (added, removed)?

like image 469
Örjan Avatar asked Apr 08 '11 10:04

Örjan


2 Answers

You have to trigger the change event manually, when you are changing the value of a select with javascript. E.g:

$('#myselect').val(10).change();

In this example the value is set to 10 and the change event is triggered. If there is an event handler attached to the select, it will be executed.

like image 102
istvan.halmen Avatar answered Sep 24 '22 13:09

istvan.halmen


Use Jquery's change function

$("#idofselect").change(function(){ });

like image 31
Bhanu Krishnan Avatar answered Sep 23 '22 13:09

Bhanu Krishnan