Solved

Setting two Dynamic Selects from PHP and Javascript

Posted on 2004-10-06
3
166 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

823 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