{"id":774,"date":"2011-04-21T14:50:55","date_gmt":"2011-04-21T18:50:55","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=774"},"modified":"2011-05-10T10:41:34","modified_gmt":"2011-05-10T14:41:34","slug":"text-box-autosugestautocomplete","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2011\/04\/text-box-autosugestautocomplete\/","title":{"rendered":"Text-box autocomplete"},"content":{"rendered":"<p>The code is initial designed by Mircho Mirev [ <a href=\"http:\/\/momche.net\">momche.net<\/a> ]. I&#8217;ve enhanced this script so instead of array of static data the text-box auto-complete uses database back end.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-771\" title=\"ScreenShot018\" src=\"http:\/\/www.iowawebnet.com\/ein\/wp-content\/uploads\/2011\/04\/ScreenShot018.gif\" alt=\"\" width=\"360\" height=\"94\" srcset=\"https:\/\/www.iowawebnet.com\/ein\/wp-content\/uploads\/2011\/04\/ScreenShot018.gif 360w, https:\/\/www.iowawebnet.com\/ein\/wp-content\/uploads\/2011\/04\/ScreenShot018-300x78.gif 300w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/p>\n<p><strong>Default.asp<\/strong><\/p>\n<blockquote><p>&lt;%@LANGUAGE=&#8221;VBSCRIPT&#8221; CODEPAGE=&#8221;65001&#8243;%&gt;<br \/>\n&lt;!DOCTYPE HTML PUBLIC &#8220;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&#8221;&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8&#8243;&gt;<br \/>\n&lt;title&gt;Intellisense Example&lt;\/title&gt;<br \/>\n&lt;SCRIPT language=&#8221;JavaScript&#8221; src=&#8221;moautocomplete.js&#8221;&gt;&lt;\/SCRIPT&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body style=&#8221;font-family: Verdana, Geneva, sans-serif; font-size: 12px;&#8221;&gt;<br \/>\n&lt;div style=&#8221;padding-top: 200px; font-family: Verdana; font-size: 12px;&#8221;&gt;<br \/>\n&lt;%<br \/>\n&#8216; Set up one data series for each category of product<br \/>\nSet objConn = Server.CreateObject(&#8220;ADODB.Connection&#8221;)<br \/>\ndbPath = Server.MapPath(&#8220;Intellisense.accdb&#8221;)<br \/>\nobjConn.Open &#8220;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&#8221; &amp; dbPath, &#8220;&#8221;, &#8220;&#8221;<br \/>\nSET objRS = Server.CreateObject(&#8220;ADODB.RecordSet&#8221;)<br \/>\nobjRS.Open &#8220;SELECT * FROM Applicants ORDER BY sProgram&#8221;,objConn,1,2<br \/>\n%&gt;<br \/>\n&lt;form method=&#8221;get&#8221;&gt;<br \/>\n&lt;b&gt;Intellisense\/autocomplete textbox&lt;\/b&gt; with db backend&lt;br \/&gt;&lt;br \/&gt;<\/p>\n<p>Scholarship Program: &lt;INPUT id=&#8221;program&#8221; type=&#8221;text&#8221; name=&#8221;program&#8221; autocomplete=&#8221;list:<br \/>\n&lt;%<br \/>\nWhile Not objRS.EOF<br \/>\nResponse.Write(objRS(&#8220;sProgram&#8221;)&amp;&#8221;|&#8221;)<br \/>\nobjRS.MoveNext<br \/>\nWEND<br \/>\n%&gt;&#8221;&gt;&lt;input type=&#8221;submit&#8221; id=&#8221;submit&#8221; value=&#8221;GO!&#8221;&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p><\/blockquote>\n<p><strong>Moautocomplete.js<\/strong><\/p>\n<blockquote><p>var cAutocomplete =<br \/>\n{<br \/>\nsDescription : &#8216;autcomplete class&#8217;<br \/>\n}<\/p>\n<p>cAutocomplete.complete = function( hEvent )<br \/>\n{<br \/>\nif( hEvent == null )<br \/>\n{<br \/>\nvar hEvent = window.hEvent<br \/>\n}<\/p>\n<p>var hElement = ( hEvent.srcElement ) ? hEvent.srcElement : hEvent.originalTarget<\/p>\n<p>var sAA = hElement.getAttribute( &#8216;autocomplete&#8217; ).toString()<br \/>\nif( sAA.indexOf( &#8216;array:&#8217; ) &gt;= 0 )<br \/>\n{<br \/>\nhArr = eval( sAA.substring( 6 ) )<br \/>\n}<br \/>\nelse if(\u00a0 sAA.indexOf( &#8216;list:&#8217; ) &gt;= 0 )<br \/>\n{<br \/>\nhArr = sAA.substring( 5 ).split( &#8216;|&#8217; )<br \/>\n}<\/p>\n<p>if( hEvent.keyCode == 16 )<br \/>\n{<br \/>\nreturn<br \/>\n}<br \/>\nvar sVal = hElement.value.toLowerCase()<br \/>\nif( hEvent.keyCode == 8 )<br \/>\n{<br \/>\nsVal = sVal.substring( 0, sVal.length &#8211; 1 )<br \/>\n}<br \/>\nif( sVal.length &lt; 1 )<br \/>\n{<br \/>\nreturn<br \/>\n}<br \/>\nfor( var nI = 0; nI &lt; hArr.length; nI++ )<br \/>\n{<br \/>\nsMonth = hArr[ nI ]<br \/>\nnIdx = sMonth.toLowerCase().indexOf( sVal, 0 )<br \/>\nif( nIdx == 0 &amp;&amp; sMonth.length &gt; sVal.length )<br \/>\n{<br \/>\nhElement.value = hArr[ nI ]<br \/>\nif( hElement.createTextRange )<br \/>\n{<br \/>\nhRange = hElement.createTextRange()<br \/>\nhRange.findText( hArr[ nI ].substr( sVal.length ) )<br \/>\nhRange.select()<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nhElement.setSelectionRange( sVal.length, sMonth.length )<br \/>\n}<br \/>\nreturn<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>cAutocomplete.init = function()<br \/>\n{<br \/>\nvar nI = 0<br \/>\nvar aInputs = document.getElementsByTagName( &#8216;INPUT&#8217; )<br \/>\nfor( var nI = 0; nI &lt; aInputs.length; nI ++ )<br \/>\n{<br \/>\nif( aInputs[ nI ].type.toLowerCase() == &#8216;text&#8217; )<br \/>\n{<br \/>\nvar sLangAtt = aInputs[ nI ].getAttribute( &#8216;autocomplete&#8217; )<br \/>\nif( sLangAtt )<br \/>\n{<br \/>\nif( document.attachEvent )<br \/>\n{<br \/>\naInputs[ nI ].attachEvent( &#8216;onkeyup&#8217;, cAutocomplete.complete )<br \/>\n}<br \/>\nelse if( document.addEventListener )<br \/>\n{<br \/>\naInputs[ nI ].addEventListener( &#8216;keyup&#8217;, cAutocomplete.complete, false )<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>if( window.attachEvent )<br \/>\n{<br \/>\nwindow.attachEvent( &#8216;onload&#8217;, cAutocomplete.init )<br \/>\n}<br \/>\nelse if( window.addEventListener )<br \/>\n{<br \/>\nwindow.addEventListener( &#8216;load&#8217;, cAutocomplete.init, false )<br \/>\n}<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The code is initial designed by Mircho Mirev [ momche.net ]. I&#8217;ve enhanced this script so instead of array of static data the text-box auto-complete uses database back end. Default.asp &lt;%@LANGUAGE=&#8221;VBSCRIPT&#8221; CODEPAGE=&#8221;65001&#8243;%&gt; &lt;!DOCTYPE HTML PUBLIC &#8220;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&#8221;&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8&#8243;&gt; &lt;title&gt;Intellisense Example&lt;\/title&gt; &lt;SCRIPT language=&#8221;JavaScript&#8221; src=&#8221;moautocomplete.js&#8221;&gt;&lt;\/SCRIPT&gt; &lt;\/head&gt; &lt;body style=&#8221;font-family: Verdana, [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,17,33,43],"tags":[30,34,37],"class_list":["post-774","post","type-post","status-publish","format-standard","hentry","category-access","category-applications","category-classic-asp","category-javascript-2","tag-access-2","tag-classic-asp-2","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/774"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=774"}],"version-history":[{"count":12,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/774\/revisions"}],"predecessor-version":[{"id":794,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/774\/revisions\/794"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}