Reputation: 67
My code works good in form select-option html code. But form input menu doesn't. Below is my code.
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
Above is good! but below is my code. why doesn't this work?? Input type="submit" doesn't work well, either. How can i overcome this problem??
<script>
same as above...
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
## Here is wrong, input element.##
<input type="text" name="users" onkeyup="showUser(this.value)>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
What is something wrong?? Help me!
Upvotes: 0
Views: 114
Reputation: 17264
You are missing an end quote
You have
onkeyup="showUser(this.value)>
Should be:
onkeyup="showUser(this.value)">
You also can't nest an <input>
inside a <select>
. See this jsfiddle and note the </select>
is in red because it is invalid. The second select in the fiddle is done correctly.
Upvotes: 2