using Metaweb.addValidationAndCompletion()

[ permalink ] [ download ]
<script src="json.js"></script>
<script src="metaweb.js"></script>
<script src="validateAndComplete.js"></script>
<script>
window.onload = function() {
    // When the document loads, set up autocompletion for our text fields
    Metaweb.addValidationAndCompletion(document.getElementById("country"),
                                       "/location/country",
                                       document.getElementById("countrymsg"));
    // Note that we add an additional constraint here
    Metaweb.addValidationAndCompletion(document.getElementById("band"),
                                       "/music/artist",
                                       document.getElementById("bandmessage")
                                       /*{genre:"Rock"}*/);
}
</script>
<style>
/* Styles for incomplete and invalid input */
input.invalid { background-color: #f88; }   /* invalid input is red */
input.incomplete {background-color: #ff8; } /* incomplete input is yellow */
span.message { font-style: italic; }
</style>
<body>
<!-- These are the input fields that do validation and completion -->
Enter a country name (or unique prefix):
<input id="country"><span id="countrymsg" class="message"></span>
<br>
Enter the name of a rock band (or unique prefix):
<input id="band"><span id="bandmessage" class="message"></span>
</body>
hits counter