good day:

I'm using an ajax script that receives a value into an input box and thus performs a function. I need to invoke the function immediately after the input box has a value. Currently the box has to lose focus in order for the function to work.

What is the correct event handler for this to work?

I have this now


which is obviously not what I need.

This is the ajax

<script type="text/javascript">
function showResult2(strs)
if (strs.length==0)
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    document.getElementById("livesearch2").style.border="1px solid #A5ACB2";

Any thoughts on this!

onblur is the lose focus event.

Why is onkeyup not what you need? Seems perfect for what you want.

Thank you for the responses and the suggestion. Unfortunately, that option does not works.

onblur works in the same manner as the onkeyup, whereas the function is invoke only after the input box has been populated and loses its focus.

I have tried also the onchange handler, this cause the function to be totally unresponsive.

I should note that these input boxes are dynamically populated with values from db. So it is not actually user inputted --not sure if that matters!

Shoud I modify anything within the ajax function itself--function include in earlier post?

Again, I want to fire the function as soon as there is value in the box not after it is exited.

Any other thoughts on this!

"I should note that these input boxes are dynamically populated with values from db. So it is not actually user inputted --not sure if that matters!"

YES! That totally matters. onkeyup is referring to the user's keyboard. It isn't working because the user's keyboard isn't being touched. Ideally you run your code at the same time the db populates the field if possible.

Otherwise you need to monitor the field(s) using setTimeOut().

<script language=javascript>
	// initialize your field variable
	var foofield='';

	// monitoring function
	function checkfoofield(){
		var currentval =;
			// field has changed
			foofield=currentval; // update the foofield var so it doesn't trigger until it's changed again
			// this is where you call your showresult2() function
	//	also using onload, or jquery document ready function set the timeout to monitor the field
	<body onload="setTimeOut('checkfoofield,200');">
<form name=myform id=myform>
FooField:&nbsp;&nbsp;<input type=text name=foo value="" id=foo size=40>

setTimeOut syntax above is not quite right:


Thank you very much for the help above. If may ask the following:

I have three fields each associated with a different function:

clientid associated with function showResult2(strs)
clientid2 associated with function showResult2(strs)
clientid3 associated with function showResult3(strss)

My apology but I'm not quite sure how I would implement this within the example you provided. Could you touch on this if possible?

Issue Resolved! Great thanks to Airshow.

Final solution below:
My populating code, --decided it was better to put everything in JQuery.

var currentClientID = false;
function getClientData() {
	var clientId = $('#clientID').val().replace(/[^0-9|a-z|A-Z]/g,'');//here to incorporate the client id with numbers and letters
	if(clientId.length >0 && clientId!=currentClientID){//here to change the client id length
			url: 'getClient.php?getClientId=' + clientId,
			type: "GET",
			success: function showClientData(response) {
				var formObj = document.forms["clientForm"];
				currentClientID = clientId;

to call the functions, I did this:

$(document).ready(function() {
	<!-- for auto suggest for typing license plate number-->
	$("#clientID").autocomplete("autocomplete_list.php", {
		width: 260,
		matchContains: true,
		selectFirst: false
			}).keyup(function() {
		//showHint(this.value);//invokes showHint on population--no keyboard action required
	}).blur(function() {
		showHint(this.value);//invokes showHint on population--no keyboard action required
		showResult(this.value);//invokes showHint on population--no keyboard action required
		showResult3(this.value);//invokes showHint on population--no keyboard action required

	$("#clientid3").blur(function() {
	$("#clientid").blur(function() {

Hope this helps someone else!

Thanks for all of the thoughtful posts!