How to add onChange attribute for select box from Javascript / jQuery
54,399
Solution 1
Did you try...
$("#depositForm").on("change", function(event) {
selectedMainDepositType(this);
} );
Solution 2
$("#depositForm").change(function(e){
selectedMainDepositType($(this));
});
Comments
-
Daya almost 4 years
I have select box with out
onChange
attribute. Now after loading the total page, based on some conditions I have to addonChange
for the select box from Javascript. I am trying with the following code, but its not working:$("#depositForm").attr(("onChange", "selectedMainDepositType('this');" ));
Its is not adding the
onChange
event.<select id="depositForm_depositSubType" class="depositSubType" style="width:160px;" name="depositSubType">
has to be changed as
<select id="depositForm_depositSubType" onchange="selectedMainDepositType(this);" class="depositSubType" style="width:160px;" name="depositSubType">
Please suggest how to add the
onChange
attribute.