Just before I jump from the roof :-)

Need some help here - autosuggest jQuery:

<!DOCTYPE html>

            <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;
                        if (self.value.length===0) {
                            timer = setTimeout(function() {
                                    type: "GET",
                                    url: "gethint.asp?q="+self.value,
                                }).done(function( hint ) {
                            }, 500);
            <h3>Start typing a name in the input field below:</h3>
            <form action=""> 
                First name: <input type="text" id="txt1" />
            <p>Suggestions: <span id="txtHint">... some content ...</span></p> 


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:

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

Just change line 12 to:

$("txtHint").text('... some content ...');

<span id="txtHint">... some content ...</span>

Yes, I understood. But I do not want to write content 2 times (see my thread above).

If I write a lot of content inside:
<span id="txtHint"> ... some content ... </ span>

... I must also write the same here:
$ ("txtHint"). text ('... some content ...');

Which is unnecessary coding ....

Okay. When your script starts, retrieve and store the content in a variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.