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);

});


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Laravel Development Companies Reviews

Among the list of Best Laravel development companies, TopDevelopers has chosen the most acclaimed laravel developers for the visitors so as to make them avail the extremely wonderful service ever offered. The web development companies listed here...

Laravel Development Company | Hire Laravel Developer

Get a free quote for custom Laravel Development Services from a trusted Laravel web development company. Hire Laravel Developers now @ best affordable rates

Laravel 6 Ajax Request Tutorial

In this post, you'll learn how to write jquery ajax form submit in Laravel 6. We will write Jquery Ajax post request Laravel 6. We will protect csrf token with Ajax request in Laravel 6. I will give you very simple example of Laravel 6 Ajax post request tutorial.