Skip to content Skip to sidebar Skip to footer

Jquery And Grails/html - Make Text Field Complete Text Like Google Does

I wanna make certain fields in my page to show me like a list of possible finishing sentences just like Google does. I think this is done via jQuery, but I'm not sure. The textfiel

Solution 1:

You will probably want to look into the jQueryUI Autocomplete widget. It has several ways of providing lists of suggestions, and there will almost certainly be something in there that will work for you.

Here's a very basic demo: http://jsfiddle.net/QU9st/

Here's the source for that:

$(function() {
    var data = "General Commodity,General Store,General Custer,General Mills".split(",");
    $("#commodity").autocomplete({
            source: data
        });
});

That demo simply uses a static string array as the datasource, but you can also use remote datasources, in formats like JSON or XML.

To get it, just drop this somewhere in your <head> tag:

<scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>

Of course, you will also need to include jQuery:

<scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Solution 2:

jQuery has an Autocomplete widget That can get it to do what you want it to do. here's an example: jQuery:

vardata = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax".split(" ");
$("#commodity").autocomplete(data);

html:

<inputtype="text"id="commodity" name="commodity">

Post a Comment for "Jquery And Grails/html - Make Text Field Complete Text Like Google Does"