フォーム内に名前を入力するためのテキストボックスがあります。テキストボックスの下のdivには、ユーザーが入力した文字から始まるAJAXを使用したデータベースからの登録ユーザーの名前が表示されます。ユーザーはユーザー名とそれらをクリックすることもできます。名前はテキストボックスに配置されます。また、divは消えます。テキストボックスのフォーカスを失うと、下に作成されたdivが消えるように、テキストボックスにonblurイベントを記述しました。これは私にとってはうまくいきます。私の問題ぼかしイベントが発生するため、下のdivから名前を選択できないということです。ユーザー名関数の選択以外の他のすべてのイベントがぼかしイベントでこれを必要とするため、onblurイベントが必要です。私のコードは次のようなものです:
<input id="venue" type="text" onkeyup="showData(this.value)"
onblur="return removediv()"/>
<div id="venuesearch">
</div>//div for displaying the set of usernames with help of AJAX
私のJavaScriptコードは次のとおりです。
function showData(str)
{
if (str.length==0)
{
document.getElementById("venuesearch").innerHTML = "";
document.getElementById("venuesearch").style.border = "0px";
return;
}
// some AJAX code here
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("venuesearch").innerHTML=xmlhttp.responseText;
document.getElementById("venuesearch").style.border="1px solid #A5ACB2";
document.getElementById("venuesearch").style.display="block";
document.getElementById("venuesearch").style.overflow="show";
}
xmlhttp.open("GET","search_venue.php?venue="+str,true);
xmlhttp.send();
}
中身search_venue.php
showVal()
列のonClickイベントで呼び出されるメソッドがあります。
function showVal(val)
{
document.getElementById("venue").value = val;
document.getElementById("venuesearch").style.display = "none";
}
function removediv()
{
document.getElementById("venuesearch").style.display="none";
return false;
}