AutoComplete Widget :: Basic JSON Implementation : AutoComplete Widget « Ajax Layer « JavaScript DHTML






AutoComplete Widget :: Basic JSON Implementation


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>AutoComplete Widget :: Basic JSON Implementation</title>
<link type="text/css" rel="stylesheet" href="./build/reset/reset.css">
<link type="text/css" rel="stylesheet" href="./build/fonts/fonts.css">
<link type="text/css" rel="stylesheet" href="./build/logger/assets/logger.css">
<link type="text/css" rel="stylesheet" href="./examples/autocomplete/css/examples.css">
<link type="text/css" rel="stylesheet" href="./docs/assets/dpSyntaxHighlighter.css">

<style type="text/css">
    #ysearchmod {position:relative;text-align:center;z-index:9050;}
    #ysearchautocomplete {position:relative;}
    #ysearchinput {position:relative;width:20em;height:1.4em;}
    #ysearchcontainer {position:absolute;left:0;top:1.7em;display:inline;}
    #ysearchcontainer .yui-ac-content {position:absolute;left:0;top:0;width:20em;border:1px solid #404040;background:#fff;overflow:hidden;text-align:left;z-index:9050;}
    #ysearchcontainer .yui-ac-shadow {position:absolute;left:0;top:0;margin:.3em;background:#a0a0a0;z-index:9049;}
    #ysearchcontainer ul {padding:5px 0;width:100%;}
    #ysearchcontainer li {padding:0 5px;cursor:default;white-space:nowrap;}
    #ysearchcontainer li.yui-ac-highlight {background:#ff0;}
    #ysearchsubmit {position:relative;}
</style>
</head>

<body>
<div id="hd">
    <h1><img src="./img/logo.gif" class="logo" alt="Y!"/><a href="./">AutoComplete Widget</a> :: JSON Data Yahoo! Search Web Services</h1>
</div>

<div id="bd">
    <!-- AutoComplete begins -->
    <div id="ysearchmod">
        <form onsubmit="return YAHOO.example.ACJson.validateForm();">
            <span>Yahoo! Search</span>
            <span id="ysearchautocomplete">
                <input id="ysearchinput">
                <div id="ysearchcontainer"></div>
            </span>
            <input id="ysearchsubmit" type="submit" value="Submit Query">
        </form>
    </div>
    <!-- AutoComplete ends -->

    <!-- Logger begins -->
    <div id="logger"></div>
    <!-- Logger ends -->

    <!-- Content begins -->
    <h3>DataSource</h3>
    <p>This DataSource instance points to Yahoo! Search Web Services, via a
    simple PHP proxy. The DataSource schema is defined for JSON data. In order
    to be compatible with the Yahoo! Search application, the DataSource's
    queryMatchContains is set to true, and the scriptQueryAppend has been
    defined to pass in additional arguments.</p>

    <h3>AutoComplete</h3>
    <p>This AutoComplete instance uses only default configuration values.</p>

    <!-- Sample code begins -->
    <div id="code">
        <h3>Sample Code</h3>

        <p>CSS:</p>
        
        <textarea name="code" class="HTML" cols="60" rows="1">
            #ysearchmod {position:relative;text-align:center;z-index:9050;}
            #ysearchautocomplete {position:relative;}
            #ysearchinput {position:relative;width:20em;height:1.4em;}
            #ysearchcontainer {position:absolute;left:0;top:1.7em;display:inline;}
            #ysearchcontainer .yui-ac-content {position:absolute;left:0;top:0;width:20em;border:1px solid #404040;background:#fff;overflow:hidden;text-align:left;z-index:9050;}
            #ysearchcontainer .yui-ac-shadow {position:absolute;left:0;top:0;margin:.3em;background:#a0a0a0;z-index:9049;}
            #ysearchcontainer ul {padding:5px 0;width:100%;}
            #ysearchcontainer li {padding:0 5px;cursor:default;white-space:nowrap;}
            #ysearchcontainer li.yui-ac-highlight {background:#ff0;}
            #ysearchsubmit {position:relative;}
        </textarea>

        <p>Markup:</p>
        
        <textarea name="code" class="HTML" cols="60" rows="1">
            <!-- AutoComplete begins -->
            <div id="ysearchmod">
                <form onsubmit="return YAHOO.example.ACJson.validateForm();">
                    <span>Yahoo! Search</span>
                    <span id="ysearchautocomplete">
                        <input id="ysearchinput">
                        <div id="ysearchcontainer"></div>
                    </span>
                    <input id="ysearchsubmit" type="submit" value="Submit Query">
                </form>
            </div>
            <!-- AutoComplete ends -->
        </textarea>

        <p>JavaScript:</p>

        <textarea name="code" class="JScript" cols="60" rows="1">
            // Instantiate an XHR DataSource and define schema as an array:
            //     ["Multi-depth.object.notation.to.find.a.single.result.item",
            //     "Query Key",
            //     "Additional Param Name 1",
            //     ...
            //     "Additional Param Name n"]
            oACDS = new YAHOO.widget.DS_XHR("./examples/autocomplete/php/ysearch_proxy.php", ["ResultSet.Result", "Title", "Summary", "Cache"]);
            oACDS.queryMatchContains = true;
            oACDS.scriptQueryAppend = "output=json&results=100"; // Needed for YWS

            // Instantiate AutoComplete
            oAutoComp = new YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", oACDS);
        </textarea>
    </div>
    <!-- Code sample ends -->
</div>
<!-- Content ends -->

<!-- Libary begins -->
<script type="text/javascript" src="./build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="./build/dom/dom.js"></script>
<script type="text/javascript" src="./build/event/event-debug.js"></script>
<script type="text/javascript" src="./build/connection/connection.js"></script>
<script type="text/javascript" src="./build/animation/animation.js"></script>
<script type="text/javascript" src="./examples/autocomplete/js/json.js"></script>
<script type="text/javascript" src="./build/autocomplete/autocomplete-debug.js"></script>
<script type="text/javascript" src="./build/logger/logger.js"></script>
<!-- Library ends -->

<script type="text/javascript">
YAHOO.example.ACJson = function(){
    var mylogger;
    var oACDS;
    var oAutoComp;
    
    return {
        init: function() {
            // Logger
            mylogger = new YAHOO.widget.LogReader("logger");

            // Instantiate an XHR DataSource and define schema as an array:
            //     ["Multi-depth.object.notation.to.find.a.single.result.item",
            //     "Query Key",
            //     "Additional Param Name 1",
            //     ...
            //     "Additional Param Name n"]
            oACDS = new YAHOO.widget.DS_XHR("./examples/autocomplete/php/ysearch_proxy.php", ["ResultSet.Result", "Title", "Summary", "Cache"]);
            oACDS.queryMatchContains = true;
            oACDS.scriptQueryAppend = "output=json&results=100"; // Needed for YWS

            // Instantiate AutoComplete
            oAutoComp = new YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", oACDS);
        },

        validateForm: function() {
            // Validate form inputs here
            return false;
        }
    };
}();

YAHOO.util.Event.addListener(this,"load",YAHOO.example.ACJson.init);
</script>

<script type="text/javascript" src="./docs/assets/dpSyntaxHighlighter.js"></script>
<script type="text/javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</body>
</html>

           
       








yui.zip( 3,714 k)

Related examples in the same category

1.Autocompleter functional tes
2.Autocompleter functional test 2
3.Auto complete textbox
4.AutoComplete Widget :: Customizable Example
5.AutoComplete Widget :: Customized XML Implementation
6.AutoComplete Widget :: JS Array Example
7.AutoComplete Widget :: JS Function Example
8.AutoComplete Widget :: Complex Flat-data Implementation
9.AutoComplete Widget :: Basic XML Implementation
10.Ajax 4 Suggest