1

I am hoping this will be a simple answer, I have used chosen drop downs for filtering the records. I have added another button for reseting the filter values.

I want to clear the chosen drop down on the "Reset" click.

I did try changing the selected values, but no luck.

Any pointers?

j0k
  • 22,600
  • 28
  • 79
  • 90

3 Answers3

2

Finally got answer to my question, it was asked in the GitHub for Choosen plugin.

Here is the code that works like charm:-

          $('.dropdownclass option:selected').removeAttr('selected');
          $('.dropdownclass').trigger('chosen:updated');

Hope this helps..

  • With newer jQuery you need to use the `.prop('selected', false);` like `$('.dropdownclass option:selected').prop('selected', false); $('.dropdownclass').trigger('chosen:updated');` – Anima-t3d Dec 22 '17 at 05:59
0

your answer:

$(".category-filter").val("")

Should work if its got the class "category-filter", and attached in the button .click() function, and within the document.ready function. - Is the option value "" actually a select option that can be selected? as I believe it needs to be for this to work?

A fiddle to show..

http://jsfiddle.net/UmV6p/3/

  • James, this works for default select box, however i am formatting it using the Choosen plugin, and code above is not having any impact so far. – Sudhir Kesharwani Jan 21 '14 at 20:29
0

You would need to first reset it and then update chosen dynamically.

$(".category-filter").val(""); 

$(".category-filter").trigger("chosen:updated");     //version v1.0.0

$(".category-filter").trigger("chzn:updated");     //other than version v1.0.0

Hope this helps.

msapkal
  • 8,268
  • 2
  • 31
  • 48