fill in 3 fields from autocomplete
I have autocomplete setup on my site. It uses some ajax functionality to supply the drop downs that is fed back in json in that my selected data is city,state abbr, zip. What I end up getting is the city field, state field fill in properly, however the zip field is the whole data string. How do I modify the data that is selected.
Here is my code.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jQuery UI Autocomplete - Remote JSONP datasource</title>
- <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
- <script src="//code.jquery.com/jquery-1.10.2.js"></script>
- <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
- <link rel="stylesheet" href="/resources/demos/style.css">
- </head>
- <body>
- <span class="ui-widget">
- <label for="city">Your city: </label>
- <input id="city">
- </span>
- <span class="ui-widget">
- <label for="state">Your state: </label>
- <input id="state">
- </span>
- <span class="ui-widget">
- <label for="zip">Your zip: </label>
- <input id="zip">
- </span>
- <script>
- $(function() {
- function log( message ) {
- //Split up message by , Set city, state, zip
- var arrMessage = message.split(",");
- document.getElementById('city').value = arrMessage[0];
- document.getElementById('state').value = arrMessage[1];
- document.getElementById('zip').value = arrMessage[2];
- }
- $( "#zip" ).autocomplete({
- source: function( request, response ) {
- $.ajax({
- dataType: "json",
- url : "Ajax.php",
- data : "zip="+document.getElementById('zip').value,
- success: function( data ) {
- response( data );
- }
- });
- },
- minLength: 4,
- select: function( event, ui ) {
- log( ui.item.label);
- }
- });
- });
- </script>
- </body>
- </html>
Thank you for looking at this.