# Autocomplete

Open me!

Demo View | Source Code (opens new window) | Download all widgets

Assets:

Images:

CSS:

JavaScripts:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
        <script type="text/javascript" src="../core/lib/jquery-1.6.2.min.js"></script>
        <script type="text/javascript" src="../core/lib/ui/libs/jquery.ui.core.min.js"></script>
        <script type="text/javascript" src="../core/lib/ui/libs/jquery.ui.widget.min.js"></script>
        <script type="text/javascript" src="../core/lib/ui/libs/jquery.ui.position.min.js"></script>
        <script type="text/javascript" src="../core/lib/ui/libs/jquery.ui.autocomplete.min.js"></script>
    
        <script type="text/javascript" src="autocomplete.js"></script>
    
        <link type="text/css" rel="stylesheet"  href="../core/lib/ui/css/ui-lightness/jquery-ui-1.8.16.custom.css">
        <link type="text/css" rel="stylesheet"  href="style.css">
        
        <title>Autocomplete</title>
    </head>
    <body>
        <h1>Autocomplete</h1>
    
        <div>
            <h3>AJAX - Demo</h3>
    
            <input id="tags-ajax-json" class="input-autocomplete">
            <br/>
            <b>Example: Kiev</b>
        </div>
        <br/>
        <hr/>
        <div>
            <h3>LOCAL - Demo</h3>
        
            <input id="tags-json" class="input-autocomplete">
            <br/>
            <b>Example: Moscow</b> 
        </div>
    </body>
    </html>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    .input-autocomplete {
        -moz-border-radius: 0px;
        -webkit-border-bottom: 0px;
        -khtml-border-bottom: 0px;
        border-radius:0px;
        border:0px;    
        background:url("../core/images/input_autocomplete.png");
        width:268px;height:18px;
        line-height:18px;
        padding:0 10px;
        font-size:11px;
        outline:none;
    }
    
    ul.ui-autocomplete {
        font-size:11px;
        border:1px solid #AAA9A9;
        background: #ffffff;
        -moz-border-radius: 4px;
    	-webkit-border-radius: 4px;
        -khtml-border-bottom: 4px;
    	border-radius: 4px;
        -webkit-box-shadow: 0px 0px 15px #aaa;
        -moz-box-shadow: 0px 0px 15px #aaa;
        -khtml-box-shadow: 0px 0px 15px #aaa;
        box-shadow: 0px 0px 15px #aaa;
    }
    
    .ui-autocomplete .ui-menu-item a {
        line-height:normal;
        border:0px;
        border-radius:0px;
        padding:2px 7px;
    }
    
    .ui-autocomplete .ui-state-hover {
        background:none;
        border:0px;
        border-radius:0px;
        line-height:normal;
        margin:0px !important;
        color:#9A9A9A;
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    
    $(function() {
        $( "#tags-ajax-json" ).autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "http://api.geonames.org/searchJSON?q=UA&country=UA&lang=en&maxRows=10&username=slv_yaroslav",
                    dataType: "jsonp",
                    data: {
                        featureClass: "P",
                        style: "full",
                        maxRows: 12,
                        name_startsWith: request.term
                    },
                    success: function(data) {
                        response($.map(data.geonames, function(item) {
                            return {
                                label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                value: item.name
                            }
                        }));
                    }
                });
    
            }
        });
        $( "#tags-json" ).autocomplete({
            source: [
                { label: "Saint Petersburg City", value: "Saint Petersburg" },
                { label: "Moscow City", value: "Moscow" },
                { label: "Kazan City", value: "Kazan" },
                { label: "Samara City", value: "Samara" },
                { label: "Omsk City", value: "Omsk" },
                { label: "Ufa City", value: "Ufa" },
                { label: "Penza City", value: "Penza" }
            ],
            open: function(event, ui) {
            }
        });
    });        
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    // Make sure to add code blocks to your code group
    Last Updated: 3/1/2021, 8:30:51 AM