Solved

Setting two Dynamic Selects from PHP and Javascript

Posted on 2004-10-06
3
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add Logo to Bookmark and Tab Headings in Browser 3 32
Make login page safer 3 34
What is define("__APPROOT__", __DIR__); 6 32
Put POST values into cookies. 14 34
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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