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
https://forums.phpfreaks.com/topic/52505-internet-explorer-onkeyup-event-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.