Google Suggest like feature using AJAX

I cranked up some code to make a google suggest like functionality using AJAX. Check out the image below:

Google Suggest using AJAX

Although its not perfectly working but you can get an idea how the things work and you can enhance it.

Here is the JavaScript code:

<script language = "javascript"> 

function GetWords(pressevent,myVal) 
{
var charCode = (pressevent.which) ? pressevent.which : (
event.keyCode);

// Check for the enter key
if(charCode!= 13) 
{
    ForumsQuestions.FillList(myVal,GetWords_CallBack)    
    
    
if(charCode == 32) 
    {

     
// Put the value from the from the DIV into the TextBox 
    
var word = document.getElementById("MyDiv").innerHTML; 
    
    document.getElementById("MyTextBox").
value = word.substring(0,word.length - 4); 

    }
}
}
function GetWords_CallBack(response) 
{
    
if(response!=null
    {
    
    document.getElementById("MyDiv").innerHTML = response.
value;  
        
    }
 
}

For the complete article please visit:


</script>

powered by IMHO

 

Print | posted @ Saturday, October 01, 2005 8:21 PM

Twitter