how to change a selections options based on another select option selected (Array)?

how to change a selections options based on another select option selected (Array)?

I have 2 select options fetched in foreach as many as my records goes. I want to change the drop down options in second select options based on what I select in first select options.

I have 2 select options fetched in foreach as many as my records goes. I want to change the drop down options in second select options based on what I select in first select options.

<select id="main[{{$user->id}}]">
   <option value="a">A</option>
   <option value="b">B</option>
   <option value="c">C</option>
<select>

select option if A is selected from first select option

<select id='sub[{{$user->id}}]'>
   <option value="1">1</option>
   <option value="2">2</option>
</select>

I tried the normal method but it works for just the first select

$('#main').change(function() {
    var options = '';
    if($(this).val() == 'a') {
        options = '<option value="1">1</option>';
    }
    else if ($(this).val() == 'b'){
        options = '<option value="2">2</option>';
    }

$('#sub').html(options);

});


jquery laravel

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Laravel Autocomplete Search With Jquery UI Example

jquery ui autocomplete laravel, jquery ui autocomplete ajax laravel, autocomplete jquery laravel, autocomplete laravel jquery, laravel autocomplete search with jquery ui example, jquery ui autocomplete example

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

How to Hire Laravel Developers and How Much Does It Cost.

Want to make the most out of the latest Laravel technology? Here is your guide on how to hire the best Laravel developer, and at the right price. 

How to perform migration rollback in laravel

Sometimes we need to rollback one specific migration. Here, in this article we will discuss about the migration rollback in laravel.

5 Laravel’s Hidden Gems

Spread the love1. Stop on first validation error By default, Laravel will check for all validation rules and return a list of errors. But if you want to stop this process after first validation failure, that’s how you can achieve…Read More→