Hi,
Just before I jump from the roof :-)
Need some help here - autosuggest jQuery:
<!DOCTYPE html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var timer;
$("#txt1").on('keyup', function(e) {
var self=this;
clearTimeout(timer);
if (self.value.length===0) {
$("txtHint").text('');
}else{
timer = setTimeout(function() {
$.ajax({
type: "GET",
url: "gethint.asp?q="+self.value,
}).done(function( hint ) {
$("#txtHint").text(hint);
});
}, 500);
}
});
});
</script>
</head>
<body>
<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1" />
</form>
<p>Suggestions: <span id="txtHint">... some content ...</span></p>
</body>
</html>
One small problem: I enter some text, but change my mind and remove everything.
When the text is removed this field appears without content:
<span id="txtHint">... some content ...</span>
Because of this code:
$("txtHint").text('');
But I want it to continue to say "... some content ..." even after I've removed the text in the text box.
Can be done with this method, but then there will be a lot of unnecessary coding:
$("txtHint").text('... some content ...');
Perhaps poorly explained, but it is still someone who can help me?
Best regards. Vetle