khore_64's avatar

I have 2 dependent selector and i want change selected dropdown 2 when i change dropdown 1

I have two dropdowns, both of which have 2 values, the first of which shows the value of 1 by default, and the second of which shows the value of 2. I want when the first dropdown is changed and for example the second value is selected, the second dropdown is changed and the value 1 is selected.

Both dropdowns display values from the database

0 likes
8 replies
jlrdw's avatar

I don't know what stack you use, but there are some good past post on dependent drop downs.

I myself would use Fetch JS, but there are also Livewire techniques to achieve the same.

What code have you tried so far?

1 like
jlrdw's avatar

When you have an onchange of first drop down, send that data to back end and retrieve the data for second drop down. Is normally how it's done.

Edit:

It looks like you only want to change the drop down 2 value when the drop down 1 changes.

Just thinking would it be easier if the user selects a value in drop down 1, and the correct value for the other drop down is retrieved from the back end and put in a text box instead of using a second drop down?

Normally dependent dropdowns are used for things like state and city, and when the state changes the second drop down is updated with the new list of cities for that State.

khore_64's avatar

Hi @jlrdw Can you give an example? I did not understand what you mean

khore_64's avatar

@jlrdw I am working with Laravel for the first time and I don't know how to solve my problem in Laravel

khore_64's avatar

@jlrdw Yes, I want to do dropdown for both. But for now, I am working on one until the problem is solved, and then I will apply it on the second one

khore_64's avatar

@Tray2 Yes. This is exactly what I want to do But this method does not work in my code. And I tried various other methods which are correct outside of my code but when it comes to my project it doesn't work and I don't understand why

Please or to participate in this conversation.