Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
- </head>
- <body>
- <form method="post">
- <input type="hidden" name="estado" id="estado" />
- Estado: <input type="text" name="estado_autocomplete" id="estado_autocomplete" /> <br />
- Município: <input type="text" name="municipio" id="municipio" /> <br />
- <input type="submit" />
- </form>
- <script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
- <script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
- <script>
- $('#estado_autocomplete').autocomplete({
- source: function (request, response) {
- $.ajax({
- url: '/teste/ajax.php?q='+$('#estado_autocomplete').val(),
- dataType: 'json'
- }).done(function(data) {
- var result = $.map( data, function( item ) {
- console.log(item);
- return {
- label: item.estado,
- value: item.id
- }
- })
- response(result);
- })
- },
- focus: function(event, ui) {
- $("#estado_autocomplete").val(ui.item.label);
- return false;
- },
- change: function(event, ui) {
- $("#estado").val(ui.item.value);
- $("#estado_autocomplete").val(ui.item.label);
- return false;
- },
- select: function( event, ui ) {
- $("#estado").val(ui.item.value);
- $("#estado_autocomplete").val(ui.item.label);
- return false;
- },
- });
- </script>
- </body>
- </html>
- <?php
- echo '<pre>' , print_r($_POST, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement