Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
Javascript Autocomplete Inputfield Variables

how can I use a value of an autocomplete inputfield in a second-inputfield?

I wrote this script below but I dont know how to use the variables from the first in the second-inputfield? the first-field responses: [{"label":"TEST","value":1}] and i need the "value" for the second field..



$(document).ready(function(){
  
  jQuery('#first-field').autocomplete({
        source:'',
        minLength: 2,
        delay:0,
        select: function(event, ui) {
                event.preventDefault();
                $("first-field").val(ui.item.label);              
        },
        focus: function(event, ui) {
                event.preventDefault();
                $("#first-field").val(ui.item.label);
        }
    });
    
       jQuery('#second-field').autocomplete({
        source:'',
        minLength: 2,
        delay:0,
        select: function(event, ui) {
                event.preventDefault();
                $("second-field").val(ui.item.label);            
        },
        focus: function(event, ui) {
                event.preventDefault();
                $("#second-field").val(ui.item.label);
        }
    });      
});

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try This

<label for="FirstField">First Name</label> <input id="FirstField" />
<br />
<br />
<label for="SecondField">Second Name</label> <input id="SecondField" />

$(function() {
    $('#FirstField, #SecondField').autocomplete({
        source: [
              "Some Name",
              "Value",
              "Place"
           ],
        minLength: 0,
        select: function( event, ui ) {
    
            $('#SecondField').val(ui.item.value);
            $('#FirstField').val(ui.item.value);
            return false;
        }
    })
    .focus(function()
    {
  var self = this;

  window.setTimeout(function()
  {
    if (self.value.length == 0)
      $(self).autocomplete('search', '');
  });
        
})
    
$('#FirstField').change(function() {
$('#SecondField').val($(this).val());
});
    
}); 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda