set options using jquery in laravel form collective

<script>
    $(document).ready(function() {

            //Make an Ajax request to a Laravel route
            //This will return the data that we can add to our Select element.
            $.ajax({
                url: 'YOUR URL GOES HERE',
                type: 'get',
                success: function(data){

                    //Log the data to the console so that
                    //you can get a better view of what the script is returning.
                    console.log(data);

                    $.each(data, function(key, value){
                        //Use the Option() constructor to create a new HTMLOptionElement.
                        var option = new Option(key, value);
                        //Convert the HTMLOptionElement into a JQuery object that can be used with the append method.
                        $(option).html(value);
                        //Append the option to our Select element.
                        $("#job").append(option);
                    });

                }
            });

        });
</script>

4
9
Scrappy 100 points

                                    //...
{!! Form::select('jobsList[]', [], null, ['id' =&gt; 'job', 'class' =&gt; 'form-control' 'multiple', 'style' =&gt; 'width: 60%; margin-top: 10px;', 'disabled'=&gt;'disabled']) !!}
..//

4 (9 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source