0

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

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
0

<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 ....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.