twistermetal
twistermetal

Reputation: 61

adding an event to select box through jquery

i am trying to add a new event to the select box, i had seen many jquery codes here on stackoverflow, but the one does not seems what i am trying to do:

here is my code try:

if ($("#Filters").find("select[multiple='multiple']").length != 0){ 
  $("#Filters").find('select[name="myselect"]').removeAttr('onChange');
  $("#Filters").find('select[name="myselect"]').attr('onChange','onmultipleoptions');               
}

I want to remove the onchange and then add again the onchange with new function called as onmultipleoptions()..

Guide

Upvotes: 1

Views: 33

Answers (1)

charlietfl
charlietfl

Reputation: 171669

You have a syntax error when creating the new onChange.

Change

.attr('onChange','onmultipleoptions')

to:

.attr('onChange','onmultipleoptions()')

You could accomplish binding the new event handler using jQuery .change(onmultipleoptions) or .on('change',onmultipleoptions) instead of replacing the attribute

DEMO

Upvotes: 1

Related Questions