Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    2 chiamate alla stessa funzione

    Ciao Ragazzi,
    il problema sono sicuro sia banalissimo ma di jQuery non ne mastico. Ho trovato il seguente codice:

    codice:
    <!doctype html>
     
    <html lang="en">
    <head>
      <meta charset="utf-8" />
      <title>jQuery UI Autocomplete - Remote JSONP datasource</title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
    
      <script>
      $(function() {
        function log( message , id ) {
    	$('input[id='+id+']').val(message);
        }
    
    	
     
        $( "#city" ).autocomplete({
          source: function( request, response ) {
            $.ajax({
              url: "http://ws.geonames.org/searchJSON",
              dataType: "jsonp",
              data: {
                featureClass: "P",
                style: "FULL",
                maxRows: 12,
                lang:"it",		
                name_startsWith: request.term
              },
              success: function( data ) {
                response( $.map( data.geonames, function( item ) {
                  return {
                    label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                    value: item.name
                  }
                }));
              }
            });
          },
          minLength: 2,
          select: function( event, ui ) {
            log( ui.item ?
              ui.item.label :
              "ERRORE",$(this).attr('id'););
          },
          
        });
      });
      </script>
    </head>
    <body>
     
    <div class="ui-widget">
      <label for="city">Your city: </label>
    
    <input id="city"  />
    <input id="city2"   />
    </div>
     
    
    </body>
    </html>

    Quando utilizzo il DOM 'city' funziona ma ora vorrei poter fare lo stesso con 'city2' quindi richiamando la stessa funzione.

    Aiutino?

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    usa una classe

    <input class="city" />
    <input class="city" />

  3. #3
    ho provato così solo che in base all'id utilizzato dovrei settare un corrispondente paramentro es se utilizzo 'city1' andrò a settare il valore di un input se utilizzo 'city2' ne setto un altro

  4. #4
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    $( "#city, #city2" )...
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  5. #5
    Funge ! Grazie mille

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.