javascript - How to make dropdownlist editable? -


i need develop application need have dropdownlist able type in data further added database table. cannot use third party controls though. can use jquery/javascript , if can how?

thank you

since tagged jquery, i'll assume jquery ui not out of question. autocomplete running combobox should want.

example taken page linked to.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jquery ui autocomplete - combobox</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <style> .custom-combobox { position: relative; display: inline-block; } .custom-combobox-toggle { position: absolute; top: 0; bottom: 0; margin-left: -1px; padding: 0; /* support: ie7 */ *height: 1.7em; *top: 0.1em; } .custom-combobox-input { margin: 0; padding: 0.3em; } </style> <script> (function( $ ) { $.widget( "custom.combobox", { _create: function() { this.wrapper = $( "<span>" ) .addclass( "custom-combobox" ) .insertafter( this.element ); this.element.hide(); this._createautocomplete(); this._createshowallbutton(); }, _createautocomplete: function() { var selected = this.element.children( ":selected" ), value = selected.val() ? selected.text() : ""; this.input = $( "<input>" ) .appendto( this.wrapper ) .val( value ) .attr( "title", "" ) .addclass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" ) .autocomplete({ delay: 0, minlength: 0, source: $.proxy( this, "_source" ) }) .tooltip({ tooltipclass: "ui-state-highlight" }); this._on( this.input, { autocompleteselect: function( event, ui ) { ui.item.option.selected = true; this._trigger( "select", event, { item: ui.item.option }); }, autocompletechange: "_removeifinvalid" }); }, _createshowallbutton: function() { var input = this.input, wasopen = false; $( "<a>" ) .attr( "tabindex", -1 ) .attr( "title", "show items" ) .tooltip() .appendto( this.wrapper ) .button({ icons: { primary: "ui-icon-triangle-1-s" }, text: false }) .removeclass( "ui-corner-all" ) .addclass( "custom-combobox-toggle ui-corner-right" ) .mousedown(function() { wasopen = input.autocomplete( "widget" ).is( ":visible" ); }) .click(function() { input.focus(); // close if visible if ( wasopen ) { return; } // pass empty string value search for, displaying results input.autocomplete( "search", "" ); }); }, _source: function( request, response ) { var matcher = new regexp( $.ui.autocomplete.escaperegex(request.term), "i" ); response( this.element.children( "option" ).map(function() { var text = $( ).text(); if ( this.value && ( !request.term || matcher.test(text) ) ) return { label: text, value: text, option: }; }) ); }, _removeifinvalid: function( event, ui ) { // selected item, nothing if ( ui.item ) { return; } // search match (case-insensitive) var value = this.input.val(), valuelowercase = value.tolowercase(), valid = false; this.element.children( "option" ).each(function() { if ( $( ).text().tolowercase() === valuelowercase ) { this.selected = valid = true; return false; } }); // found match, nothing if ( valid ) { return; } // remove invalid value this.input .val( "" ) .attr( "title", value + " didn't match item" ) .tooltip( "open" ); this.element.val( "" ); this._delay(function() { this.input.tooltip( "close" ).attr( "title", "" ); }, 2500 ); this.input.data( "ui-autocomplete" ).term = ""; }, _destroy: function() { this.wrapper.remove(); this.element.show(); } }); })( jquery ); $(function() { $( "#combobox" ).combobox(); $( "#toggle" ).click(function() { $( "#combobox" ).toggle(); }); }); </script> </head> <body> <div class="ui-widget"> <label>your preferred programming language: </label> <select id="combobox"> <option value="">select one...</option> <option value="actionscript">actionscript</option> <option value="applescript">applescript</option> <option value="asp">asp</option> <option value="basic">basic</option> <option value="c">c</option> <option value="c++">c++</option> <option value="clojure">clojure</option> <option value="cobol">cobol</option> <option value="coldfusion">coldfusion</option> <option value="erlang">erlang</option> <option value="fortran">fortran</option> <option value="groovy">groovy</option> <option value="haskell">haskell</option> <option value="java">java</option> <option value="javascript">javascript</option> <option value="lisp">lisp</option> <option value="perl">perl</option> <option value="php">php</option> <option value="python">python</option> <option value="ruby">ruby</option> <option value="scala">scala</option> <option value="scheme">scheme</option> </select> </div> <button id="toggle">show underlying select</button> </body> </html> 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -