Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Chosen focus on page load (onLoad?)

I'm using the Jquery Chosen plugin on a select box, however I'd like to focus this on page load. I've used the following code to focus a text input:

onLoad="document.forms.sales_order_form.customer.focus()"

But this doesn't work for the select box:

<select data-placeholder="Select a Customer..." class="chzn-select" name="customer" style="width:400px;">
    <option value=""></option>
</select>
like image 883
Ross Avatar asked Nov 26 '11 21:11

Ross


2 Answers

In Chosen 1.0, this command is now:

$('.my_select_box').trigger('chosen:activate');

See here.

like image 134
Drew Johnson Avatar answered Oct 29 '22 04:10

Drew Johnson


If your using the first example (standard select box) you can use:

jQuery(document).ready(function($) {
    $('.chzn-drop .chzn-search input[type="text"]').focus();
})
like image 26
noob Avatar answered Oct 29 '22 04:10

noob