Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting two Dynamic Selects from PHP and Javascript

Posted on 2004-10-06
3
Medium Priority
?
177 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

926 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