Solved

Setting two Dynamic Selects from PHP and Javascript

Posted on 2004-10-06
3
165 Views
Last Modified: 2006-11-17
Hi all, trying to create two select dropdowns in a profile.

Mission is to update the second select dropdown with a selection of models relating to the selected make for the first select dropdown (without page refresh if possible) and then update the members profile in the database with these values.

Currently I have two functions (see below) that are working fine to update both seperate fields, but I am at a lost trying to combine them into one, so any help would be great.

The "make" table contains "id", and "make" fields; with the "model" table containg "id", "make_id", "model", where the model is matched to the make on make_id, if that helps.

An example of how it should work can be seen on this site: http://www.nissanusa.com/vehicles/Configurator/1,9442,,00.html

Thankyou for any help you can provide :)

Two functions I am currently using called from a PHP file as:
      'MAKE' => vehicle_make_select($garage_userdata['make']),
      'MODEL' => vehicle_model_select($garage_userdata['model']),
and shown by a template.

function vehicle_make_select($default, $select_name = 'make')
{  
        global $db, $lang;
               
        $sql = "SELECT id, make
              FROM " . GARAGE_MAKES_TABLE . "
                ORDER BY make";    
      if ( !($result = $db->sql_query($sql)) )
      {
            message_die(GENERAL_ERROR, 'Could not obtain list of Car Makes.', '', __LINE__, __FILE__, $sql);
    }
       
        $vehicle_make_select ='<select name="' . $select_name . '">';
    $vehicle_make_select .= '<option value="">' . $lang['C_Select_make'] . '</option>';
       while ( $row = $db->sql_fetchrow($result) )
        {  
             $selected = ( $row['id'] == $default ) ? ' selected="selected"' : '';
            $vehicle_make_select .= '<option value="' . $row['id'] . '"' . $selected . '>' . $row['make'] . '</option>';
      }
      $vehicle_make_select .= '</select>';
        return $vehicle_make_select;
}


function vehicle_model_select($default, $select_name = 'model')
{  
        global $db, $lang;
 
        $sql = "SELECT *
              FROM " . GARAGE_MODELS_TABLE . "
               ORDER BY model";
         
      if ( !($result = $db->sql_query($sql)) )
      {
            message_die(GENERAL_ERROR, 'Could not obtain list of Car Models.', '', __LINE__, __FILE__, $sql);
    }

        $vehicle_model_select ='<select name="' . $select_name . '">';
    $vehicle_model_select .= '<option value="">' . $lang['C_Select_model'] . '</option>';
       while ( $row = $db->sql_fetchrow($result) )
        {
          $selected = ( $row['id'] == $default ) ? ' selected="selected"' : '';
          $vehicle_model_select .= '<option value="' . $row['id'] . '"' . $selected . '>' . $row['model'] . '</option>';
    }
        $vehicle_model_select .= '</select>';
        return $vehicle_model_select;
}


0
Comment
Question by:Skotch5
3 Comments
 
LVL 4

Accepted Solution

by:
Georgiana Gligor earned 125 total points
ID: 12246136
hi

try reading these questions:

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20730818.html

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20323861.html
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20908383.html
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20938739.html
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_10354063.html

and their answers, this is what I found on a quick search on the site.

If none of these suits you, I'll be glad to help you write your own, as I have done that before. I'm just a bit time pressed right now.

Cheers,
     Georgiana
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

705 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

18 Experts available now in Live!

Get 1:1 Help Now