jquery autocomplete combobox get current input value -


is possible current input value user typed?

problem if combobox didn't last focus possible on clicking enter submit form , need validate user wrote isn't choose in dropdown list.

yes, grab val() of search field's <input> element.

in below example, used keyup event check if user pressed enter key, , use trigger want: grab current contents of search field.

if field has been emptied, can use other trigger grab contents of field (remember, normal <input> tag) , perhaps store hidden input field safe keeping. then, when ready, read value stored in hidden input field same way read non-hidden input field in example below.

field read: <input id="tags">

method read it: strsrxfield = $("#tags").val();

jsfiddle demo

example:

html:

<div class="ui-widget">   <label for="tags">tags: </label>   <input id="tags"> </div> 

jquery/javascript:

var availabletags = [     "actionscript",     "applescript",     "asp",     "basic",     "c",     "c++",     "clojure",     "cobol",     "coldfusion",     "erlang",     "fortran",     "groovy",     "haskell",     "java",     "javascript",     "lisp",     "perl",     "php",     "python",     "ruby",     "scala",     "scheme" ];  $( "#tags" ).autocomplete({     source: availabletags });  $('#tags').keyup(function(e) {     var keycode = (e.keycode ? e.keycode : e.which);     if(keycode == '13'){         var srx = $('#tags').val(); //in fn, use $(this).val()         alert('you entered: ' + srx);     } }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -