Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <html>
  2. <title>Auto completar</title>
  3. <head>
  4. <script src="js/jquery-1.7.1.min.js"></script>
  5. <script src="js/jquery.ui.core.min.js"></script>
  6. <script src="js/jquery.ui.widget.min.js"></script>
  7. <script src="js/jquery.ui.position.min.js"></script>
  8. <script src="js/jquery.ui.autocomplete.min.js"></script>
  9. <link rel="stylesheet" href="css/jquery-ui-1.8.16.custom.css"/>
  10. </head>
  11. <body>
  12. <script>
  13.  
  14. $(function() {
  15.  
  16. $( "#input_estados" ).autocomplete(
  17. {
  18. source:'estados.php',
  19. select: function( event, ui ) {
  20. $( "#input_estados" ).val( ui.item.estado + " / " + ui.item.uf );
  21. $( "#hidden_uf" ).val( ui.item.id );
  22. return false;
  23. }
  24. }).data( "autocomplete" )._renderItem = function( ul, item ) {
  25. return $( "<li></li>" )
  26. .data( "item.autocomplete", item )
  27. .append( "<a><strong>" + item.estado + "</strong> / " + item.uf + "</a>" )
  28. .appendTo( ul );
  29.  
  30. };
  31.  
  32. $( "#input_municipios" ).autocomplete(
  33. {
  34. source:'municipios.php?uf='+$( "#hidden_uf" ).val(),
  35. select: function( event, ui ) {
  36. $( "#input_municipios" ).val(ui.item.municipio);
  37. return false;
  38. }
  39. }).data( "autocomplete" )._renderItem = function( ul, item ) {
  40. return $( "<li></li>" )
  41. .data( "item.autocomplete", item )
  42. .append( "<a><strong>" + item.municipio + "</strong></a>" )
  43. .appendTo( ul );
  44. };
  45.  
  46. });
  47.  
  48. </script>
  49. <form method="get" value"#">
  50. Estado: <input type="text" id="input_estados" /> <br>
  51. Cidade: <input type="text" id="input_municipios" /> <br>
  52. <input type="text" id="hidden_uf"><br>
  53. <button onclick="faz()">teste</button><script>function faz() { alert($("#hidden_uf").val()); } </script>
  54. </form>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement