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

239
Views
How to autopopulate a dropdown with jquery in laravel?

I have this controller function:

public function showclientsinvoice($id)
{
    $clients = Clients::find($id);

    return response()->json($clients);
}

That makes me autopopulate the input fields with clients data.

My problem is I don't know how to autopopulate a dropdown list

My jquery script is this:

 $(document).ready(function () {
        
        $('body').on('click', '#show-client', function () {
          var userURL = $(this).data('url');
          $.get(userURL, function (data) {
              $('#invoicemodal').modal('show');
              $('#client-id').val(data.id);
              $('#client-name').val(data.nume);
              $('#client-ctara').val(data.tara);
              $('#cif').val(data.cif);
              $('#cif1').val(data.cif1);
              $('#rgc').val(data.rgc);
              $('#rgc1').val(data.rgc1);
              $('#rgc2').val(data.rgc2);
              $('#rgc3').val(data.rgc3);
              $('#cp').val(data.cp);
              $('#judet').val(data.judet);
            
            
          })
         
       });
        
    });
   
</script>

How can I integrate in this script an autopopulate for dropdown?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use JQuery in this way to add dynamically dropdown options:

let options = {
    a : 'one',
    b : 'two'
};
var select = $('#idselect');
$.each(options, function(val, text) {
    select.append(
        $('<option></option>').val(val).html(text)
    );
});
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!