JQuery Dropdown Scale for Search

I have a search list created using jQuery Plugin: http://plugins.jquery.com/searchit/

But I want some value to be selected by default when the list box first appears. Even though I selected this in the options tag (Rockford in ex below). This part does not work.

See here for an example:

http://jsfiddle.net/QuYJD/22/

$("select").searchit( { textFieldClass: 'searchbox' } ); Type the search text: <br/> <select id="listBox1"> <option>Robinhood</option> <option selected >Rockford</option> <option>Rome</option> <option>Ronda</option> <option>Rondon</option> <option>Rondonopolis</option> <option>Rongelap</option> </select> 

Any idea? Or any other solution ...

+4
source share
2 answers

Some hacker way

Perhaps you could do something like this after starting the plugin:

 $(".searchbox").val($("#listBox1 :selected").val()) 

Since this plugin seems to make you select as follows:

 <input type="textbox" id="__searchit2" class="searchbox"> <div id="__searchitWrapper2" style="display: none; vertical-align: top; overflow: hidden; border: 1px solid rgb(128, 128, 128); position: absolute;"> <select id="listBox2" style="padding: 5px; margin: -5px -20px -5px -5px;"> <option>Robinhood</option> <option>Rockford</option> <option selected="">Rome</option> <option>Ronda</option> <option>Rondon</option> <option>Rondonopolis</option> <option>Rongelap</option> </select> </div> 

Plugin change

I added another plugin option called selected . If you set it to true , then the text box will display the selected option . Just add this extra option:

 $("select").searchit({ textFieldClass: 'searchbox', selected: true }); 

Demo: http://jsfiddle.net/hungerpain/QuYJD/23/

+2
source

You can check the selected plugin for jQuery. Its more convenient and convenient interface.

It has the function you are looking for. For more information, click on the following link.

http://harvesthq.imtqy.com/chosen/

+23
source

Source: https://habr.com/ru/post/1493828/


All Articles