I have select box with out onChange
attribute. Now after loading the total page, based on some conditions I have to add onChange
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.
Yes. Add an onChange property to the first select, then use it to call a javascript function you have written elsewhere.
The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.
Definition and UsageThe onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.
No; the onchange attribute is only applicable to form field elements ( input , select , textarea , etc). Thanks for your answer.
Did you try...
$("#depositForm").on("change", function(event) {
selectedMainDepositType(this);
} );
jQuery .on()
$("#depositForm").change(function(e){
selectedMainDepositType($(this));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With