Need help on PHP <select> onchange function

Discussion in 'PHP' started by theauthor, Jan 26, 2011.

  1. #1
    Hi, I need a help from experts as I'm not so good in php language. I'm making a site for myself and stopped when a critical point came to me.

    I have 2 tables in a database.

    Table 1 name: brands
    brand_id brand_name
    -------- ------------
    1 Toyota
    2 Nissan
    3 Mitsubishi

    Table 2 name: models
    model_id model_name brand_id
    -------- ------------ --------
    1 Land Cruiser 1
    2 Allion 1
    3 Murano 2
    4 Patrol 2
    5 Pajero 3
    6 Corolla 1



    in the FORM page -

    1. Select car brand :
    <select name="carbrand">
    <option>Toyota</option>
    <option>Nissan</option>
    <option>Mitsubishi</option>
    </select>

    2. Select car model:
    <select name="carmodel">
    <option>Land Cruiser</option>
    <option>Allion</option>
    <option>Corolla</option>
    </select>

    Now, describing what I really want to do-

    1. I have a form page and insert car brand, model into 3rd table
    2. the 1st list shows car brands from table brands.
    3. while I select (just a single click) any brand name, the query will pick model names from table models matching brand_id from both tables and be listed into 2nd list box.
    4. Then I select model name and insert the records into 3rd table.

    I think I could write clearly. If any asking, please let me know. I'll be very glad to them who can help me.

    Thanks in advance
    Chris
     
    theauthor, Jan 26, 2011 IP
    falconlink likes this.
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    so just post solution here...

    theauthor - you should use ajax if you wouldn't like to reload whole pages, but there are a lot of tutorials. try to search ;)
     
    G3n3s!s, Jan 27, 2011 IP
  3. theauthor

    theauthor Member

    Messages:
    10
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    Thank you G3n3s!s

    I got a good tutorial and also used ajax. Thanks for your suggestion.
     
    theauthor, Feb 4, 2011 IP