Populate the selectbox dynamically using chosen.js - jquery

311
November 23, 2016, at 5:21 PM

I can change the placeholder after page has loaded (shown below),

$('#dropdown1').chosen();
$('#dropdown1').attr('data-placeholder', 'Pizza , Chips');
$('#dropdown1').trigger('chosen:updated');

But cant seem to add some values taken from a database. I want them to bee added straight to the text box, so they look like they have already been selected. They should look square and grey and can be deselected if wished....???

Answer 1

The answer is so simple, but took me a while, was thinking I had to do it via jquery when all it was was adding one word "Selected" in the option!

<select class="html-multi-chosen-select" multiple="multiple">
  <option value="foo" selected>foo</option>
  <option value="bar" selected>bar</option>
  <option value="dog">dog</option>
  <option value="cat">Cat</option>
</select>

Fiddle here http://jsfiddle.net/mikeys4u/99Dkm/235/

READ ALSO
Owl Carousel 2 - how to get a current item?

Owl Carousel 2 - how to get a current item?

I am working on a web site with Owl Carousel 2. [nnn]I just want to detect which item is displayed on the front.

960
Fade in elements when they come into viewport

Fade in elements when they come into viewport

I'm trying to fade in elements with the class of "fade-me" whenever those elements come into view. I found this fiddle: http://jsfiddle.

289
Trigger an ad for the first click on ANY part of the website

Trigger an ad for the first click on ANY part of the website

There are some websites where no matter where I click (background, random words, existing links, anything) an ad pops up. For example: first time I click Contact I get the Spam, but if I click Contact again I will actually go to "/contact" section.

189
How to make console run script in the background?

How to make console run script in the background?

I want to block some pop-up stuff, by removing a specific css file. .

317