jQuery UI ComboBox
by Amit Vishwakarma
HTML
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/smoothness/jquery-ui.css">
<select id="combobox" name="scheme_name" style="width:300px" class="forminput">
<option value="Select" >amit</option>
<option >vishwakarma</option>
<option >mohsin</option>
<option >khan</option>
</select>
CSS
body {font-size:10px;}
.ui-combobox {
position: relative;
display: inline-block;
}
.ui-combobox-button {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
/* adjust styles for IE 6/7 */
*height: 1.7em;
*top: 0.1em;
}
.ui-autocomplete-input {
margin: 0;
padding: 0.3em;
}
JavaScript
(function($) {
$.widget("ui.combobox", {
_create: function() {
var input, self = this,
select = this.element.hide(),
selected = select.children(":selected"),
value = selected.val() ? selected.text() : "",
wrapper = $("<span>").addClass("ui-combobox").insertAfter(select);
input = $("<input>").appendTo(wrapper).val(value).addClass("ui-state-default").autocomplete({
delay: 0,
minLength: 0,
source: function(request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text))) return {
label: text.replace(
new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
value: text,
option: this
};
}));
},
select: function(event, ui) {
ui.item.option.selected = true;
self._trigger("selected", event, {
item: ui.item.option
});
},
change: function(event, ui) {
if (!ui.item) {
var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
valid = false;
select.children("option").each(function() {
if ($(this).text().match(matcher)) {
this.selected = valid = true;
return...