27.10.2015 Views

AJAX and PHP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6<br />

}<br />

}<br />

else<br />

// FF<br />

if (oText.setSelectionRange)<br />

{<br />

oText.setSelectionRange(start, length);<br />

}<br />

oText.focus();<br />

/* function that autocompletes the typed keyword*/<br />

function autocompleteKeyword()<br />

{<br />

//retrieve the keyword object<br />

var oKeyword = document.getElementById("keyword");<br />

// reset the position of the selected suggestion<br />

position=0;<br />

// deselect all suggestions<br />

deselectAll();<br />

// highlight the selected suggestion<br />

document.getElementById("tr0").className="highlightrow";<br />

// update the keyword's value with the suggestion<br />

updateKeywordValue(document.getElementById("tr0"));<br />

// apply the type-ahead style<br />

selectRange(oKeyword,httpRequestKeyword.length,oKeyword.value.length);<br />

// set the autocompleted word to the keyword's value<br />

autocompletedKeyword=oKeyword.value;<br />

}<br />

/* function that displays an error message */<br />

function displayError(message)<br />

{<br />

// display error message, with more technical details if debugMode is true<br />

alert("Error accessing the server! "+<br />

(debugMode ? "\n" + message : ""));<br />

}<br />

11. The code is ready for testing now. Load the address http://localhost/ajax/<br />

suggest/ with a web browser. Let's say, you're looking for the help page of strstr.<br />

After typing s, you're shown a list of functions that start with this letter:<br />

181<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!