I have added a suggestion list to my text box. With my script I am getting suggestion, But on blur if text is type other than suggested list it removed from my text box and value becomes blank of text box.
<input name="poetname" type="text" id="poetname" maxlength="80" onkeyup="lookup(this.value);" onblur="fill();" style="display:none;"/>
<div class="suggestionsBox" id="suggestions" style="display: none;"><img src="images/upArrow.png" style="position: relative; top: -12px; left: 50px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList"> </div>
</div>
My lookup function
function lookup(poetname) {
if(poetname.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
//alert("Hiiii");
$.post("rpc.php", {queryString: ""+poetname+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}
My fill function
function fill(thisValue) {
$('#poetname').val(thisValue);
setTimeout("$('#suggestions').hide();", 500);
}
I wish if value entered other than suggestion in my text box than on blur my text box shouldn’t be empty or null.
You’ve not passed a parameter into fill, it should be onblur=”fill(this.value);”