Jump to content

Internet Explorer onkeyup() event problem...


js_280

Recommended Posts

I'm new to AJAX and using the following code for a autocomplete field works in Firefox, however, only the first letter that is entered is recognized in IE 6 and 7

 

Here's the code...

 


<script type="text/javascript" language="javascript">

var XMLRequest = false;

try
{
	XMLRequest = new XMLHttpRequest();
}
catch(e)
{
	try
		{
			XMLRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e2)
		{
			try
				{
					XMLRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e3)
				{
					alert("Not AJAX compatible!");
				}
		}
}

function sendRequest()
{
	var search = false;
	search = document.getElementById('search').value;
	if(search != "")
		{
			var url = "./dynamic_lookup_script.php?search=" + escape(search);
			document.getElementById('display_div').style.visibility = "visible";

			XMLRequest.onreadystatechange = function()
				{
					if(XMLRequest.readyState == 4)
						{
							document.getElementById('display_div').innerHTML = XMLRequest.responseText;
						}				
				}

			XMLRequest.open("GET", url, true);
			XMLRequest.send(null);
		}
	else
		{
			document.getElementById('display_div').style.visibility = "hidden";
		}
}

</script>

</head>

<body onload="document.getElementById('search').focus(); document.getElementById('search').value = '';">
Customer Name:   <input type="text" name="search" id="search" onkeyup="sendRequest();" /><br />

<div id="display_div" style="padding: 10px; width: 300px; left: 124px; height: auto; position: absolute; background-color: #DDDDFF; border: 1px solid #0066FF; font-size: 10px; font-weight: bold; visibility: hidden;"></div>

 

When you enter the first letter into the search field, it will pull the first query.  After that, the display doesn't update in IE.  Is there something else other than onkeyup() I should be using to query on every keypress?

 

Thanks for the help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.