11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete}var keyword = document.getElementById("keyword").value;// check to see if the keyword is emptyif(keyword == ""){// hide the suggestionshideSuggestions();// reset the keywordsuserKeyword="";httpRequestKeyword="";}// set the timer for a new checksetTimeout("checkForChanges()", 500);// check to see if there are any changesif((userKeyword != keyword) &&(autocompletedKeyword != keyword) &&(!isKeyUpDownPressed))// update the suggestionsgetSuggestions(keyword);/* function that h<strong>and</strong>les the keys that are pressed */function h<strong>and</strong>leKeyUp(e){// get the evente = (!e) ? window.event : e;// get the event's targettarget = (!e.target) ? e.srcElement : e.target;if (target.nodeType == 3)target = target.parentNode;// get the character code of the pressed buttoncode = (e.charCode) ? e.charCode :((e.keyCode) ? e.keyCode :((e.which) ? e.which : 0));// check to see if the event was keyupif (e.type == "keyup"){isKeyUpDownPressed =false;// check to see we if are interested in the current characterif ((code < 13 && code != 8) ||(code >=14 && code < 32) ||(code >= 33 && code = 112 && code =0){location.href = document.getElementById("a" + position).href;}}else// if the down arrow is pressed we go to the next suggestionif(code == 40){newTR=document.getElementById("tr"+(++position));oldTR=document.getElementById("tr"+(--position));// deselect the old selected suggestionif(position>=0 && position

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

Saved successfully!

Ooh no, something went wrong!