I want to select an option from select randomly.
<select class=".sel" id="sel">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
actually i am using jQuery autocomplete.
Well,the question is how can i select option randomly from a select box ?
and what i tried is
function change_something(opt)
{
var randomOption=Math.floor(Math.random()*$(opt+' option').size());
$(opt+ option["value='"+randomOption+"'"]).attr('selected', 'selected');
}
Actually i am not a jQuery expert,so i am getting failed to change something .
That's what you need
Also, use class="sel" instead of class=".sel"
This will work with your HTML example snippet.
Something like this should work:
http://jsfiddle.net/elclanrs/8DPMN/
Change your class from ".sel" to "sel", then Try: