Second list box values changing according to selection of first list box

Posted on 2005-04-21
Last Modified: 2008-02-01

I have simple table that lists cars, trucks etc. I would like to put those values to list box. And I want to have another list box as well. If user selects cars, it will go to another table and read cars there and list them at second list box. If user select trucks, it will automatically select trucks from table and list them at second list box.

If you could please help, it will be great.

Question by:hasozduru
    LVL 12

    Accepted Solution

    list1 (for selecting car or trucks)

    list2 (for showing the cars..)

    list3 (for showing the trucks..) right?

    you can do that using only one list box,!

    when the user select something in the list1, fetch all data needed from the     db and fill it in the list2.  


    <select name="sel1">
    <option value="car">Car</option>
    <option value="truck">Truck</option>

    <select name="sel2">
    if ($selected_option=="car")
    //select query for car
    }elseif ($selected_option=="truck")
    //select query for truck

    <option value="<?php $row[0]?>"><?php $row[0]?></option>

    Author Comment

    This example did not help me. I am looking for something like at site. Please visit and select "from" list box and see how "to" list box changes according to "from" one.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now