Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!