Changing value of select box in Zurb's Foundation via JavaScript

user225269 picture user225269 · Oct 10, 2012 · Viewed 7.2k times · Source

I'm having difficulty changing the value of select box in Zurb's foundation. I'm using the custom forms which just hides the actual select box and uses an unordered list as the select box. My problem is that the usual method of changing the value of select box doesn't work:

$('#selectboxID').val('something')

The code above assumes that the value of each of the options in the select box is the same with the text:

<option value="1">1</option>

I also tried:

$($('.dropdown ul li')[1]).addClass('current') 

$($('.dropdown ul li')[0]).removeClass('current') //remove current class from the other one

But it doesn't work either.

Answer

Marcin Raczkowski picture Marcin Raczkowski · May 15, 2013

There's also alternative use case when you're binding on change event yourself, you might not want to trigger it. Code to just force a refresh on select:

Foundation.libs.forms.refresh_custom_select(@jQueryElement, true)

where @jQueryElement is a original hidden select.