/* This is the JavaScript file for the AJAX Suggest Tutorial You may use this code in your own projects as long as this copyright is left in place. All code is provided AS-IS. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For the rest of the code visit http://www.DynamicAJAX.com Copyright 2006 Ryan Smith / 345 Technical / 345 Group. */ //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?"); } } //Our XmlHttpRequest object to get the auto suggest var searchReq = getXmlHttpRequestObject(); //Called from keyup on the search textbox. //Starts the AJAX request. function searchSuggest() { if (searchReq.readyState == 4 || searchReq.readyState == 0) { var str = escape(document.getElementById('txtSearch').value); if (str.length >= 3) { searchReq.open("GET", '/js/hsuche.php?eingabe=' + str, true); searchReq.onreadystatechange = handleSearchSuggest; searchReq.send(null); } } } function handleSearchSuggest() { if (searchReq.readyState == 4) { var ss = document.getElementById('search_suggest'); var str = searchReq.responseText.split("\n"); if (str.length > 1) { ss.innerHTML = '
Bitte wählen Sie ein Handy!     Anzeige löschen
'; } else { ss.innerHTML = '
Kein Handy im aktuellen Angebot gefunden!     Anzeige löschen
'; } for(i=0; i < str.length - 1; i++) { str[i]=str[i].split('|'); if (str[i][0] != '-') { //Build our element string. This is cleaner using the DOM, but //IE doesn't support dynamically added attributes. var suggest = '

' + str[i][0] + '

'; ss.innerHTML += suggest; } } } } //Click function function setSearch(value) { value=myvalue[0]; document.getElementById('txtSearch').value = value; document.getElementById('search_suggest').innerHTML = ''; }