View Single Post
Old 02-10-2009, 09:27 AM   PM User | #1
brazenskies
Regular Coder

 
Join Date: May 2008
Location: Oxford, UK
Posts: 422
Thanks: 14
Thanked 27 Times in 27 Posts
brazenskies is on a distinguished road
Using onkeypress to submit ajax request

I'm new to ajax and having a bit of trouble with the 'onkeypress' event.

Here's the scenario...

User enters a search value into a text box, then clicks on an image to submit the request.

Image code...

Code:
<img src="images/btnTownSearch.jpg" alt="Submit Search"  style="margin-top:4px;" onclick="runSearch()" />
function code...

Code:
function runSearch(){	
		if (document.frmSearch1.txtCP.value != "")
			{
				http = createRequestObject();
				http.open('get', 'maptools/searchLocation.asp?search=' + document.frmSearch1.txtCP.value ); 
				http.onreadystatechange = handleSearchResponse;
				http.send(null);
			}
		else
			{
				alert("Please choose a centre point")
			}
	}
This works perfectly if you click on the image but I somehow need to modify the code to allow the request to be made when the user hits the 'enter' key.

Also, if it helps at all then here's a link to my page.

Any help would be appreciated,
Thanks in advance!
brazenskies is offline   Reply With Quote