I am writing a combobox that gets a list of movies from a database that contain the text that was typed on an input box. The comboxbox should drop down when the user select in the input box and hide when the input box goes out of focus. The problem is that when the user clicks on a item to select it, the input will get out of focus, the combobox hides and the click is lost. So I wonted to wait for all clicks to be processed before hiding the combobox. I have added a seTimeout do delay the hidding by 1s, but this is not very good because 1s is a bit long and lower values may make the combobox hide before the click. Here is my code:
<script>
function make_combobox() {
$.get("/Clients/make_movies_table", { search_str: mov_text_sel.value }, function (data, status)
{
mov_sel.innerHTML=data;
});
$("#mov_sel").show();
}
function hide_combobox() {
setTimeout(function () {
$('#mov_sel').hide();
}, 1000);
window.
}
</script>
<input type="text" id="mov_text_sel" size="10"
onfocus="make_combobox()"
oninput="make_combobox()"
onblur="hide_combobox()"
/>
<div style="position:relative">
<div id="mov_sel">
</div>
</div>
and the code for a combobox row:
<td class="combobox"
onmouseover="this.style.backgroundColor = 'RoyalBlue'"
onmouseout="this.style.backgroundColor = 'white'"
onclick="mov_text_sel.value = '@rec.Title'">
@rec.Title
</td>
Aucun commentaire:
Enregistrer un commentaire