jQuery Chosen plugin add options dynamically with out using Ajax?

admin

Administrator
Staff member
first of all this is not a duplicate question. i checked all the available questions i didn't find the solution.

My Problem is, i am working in a project which is using
Code:
Jquery choosen
plug-in
Code:
version 1.5.1
to create multiple select form fields. in some
Code:
multi select fields
i need to add options dynamically if the option not available in the list. for example<br>

i have a
Code:
tags
field with 3 options<br>
1. male<br>
2.female<br>
3.kids but i am allowing user can able to add any new tag like
Code:
young
Code:
baby
for this field. to achieve this i did like this in following tutorial
<a href="https://boundlessjourney.wordpress.com/2014/06/12/adding-new-values-to-chosen-plugin/" rel="nofollow">add attributes dynamically in using chosen plugin</a>.

this is working fine. but the problem is this is adding new values in all
Code:
multi-select
fields. some fields like
Code:
products
should not allow to add. i have a very less fields to add dynamic values. so want to impliment that
Code:
case 13
logic in the form itself to add tags. till now i tried like this

Code:
$('#product_tags').on( "keypress", function (e) {

  if (e.which == 13) {
    e.preventDefault();
    $('#product_tags').empty();
    $('#product_tags').append('&lt;option&gt;' + $(evt.target).val() + '&lt;/option&gt;');
    $('#product_tags').trigger("chosen:updated");
  }
});

its not working. how can i achieve this?? any help would be well appreciate.. thank you