简体   繁体   中英

populating the values in second select box according to previous select box using database in PHP

I have database name compare and in that, I have tables compare1 and model1 in the compare1 table, I have the brand of mobiles like Samsung and Micromax and in model1 i have models of Samsung brand and Micromax brand such as Samsung Galaxy and Micromax x560 etc.

Now i have a 2 select box which has values which fetch from the database and display in it. in a first select box all brand is fetched and in the second select box, all models is fetched.

now the problem is i want to select the only models in the second select box on the base of brand chosen in the first select box.

for example, if i choose a brand(Samsung) in first select box then in a second select box there should be only Samsung galaxy, Samsung note, Samsung champ etc..

Note all the values is fetched from databases only

I don't know how it's possible ima newbie any help is appreciated. thankyou.

You have two options for this, both will require jQuery.

  1. You can use an AJAX call to refetch the second list each time the first option is changed, OR

  2. You can load all brands of your phones into the second box, with a data attribute like brand="Samsung" and then use jQuery to hide the ones from the brand that's not picked.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM