Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

form select active value

Avatar of aarondarr
aarondarr asked on
7 Comments1 Solution294 ViewsLast Modified:

I have a select that pulls options from a table in our drupal database.

basically I want to run an if statement from the value of the select without submitting the form, I think an onchange event would do it, just unsure of how to do it?

function my_selector($default = NULL) {

  // Prepare the <select> options array 
  $options = array();
  // Write some SQL to get the options you desire and run thequery
  $sql = "SELECT id, code, description FROM {association_code} ORDER BY id";
  $r = db_query($sql);
  // Get each option and populate the options array.
  while ($row = db_fetch_array($r)) {
    $options[$row['code']] = $row['description'];
  // Start making the FormAPI form.
  $form['my_select'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#title' => t('Select your code'),
  // Return the form to Drupal's FormAPI.
  return $form;

return drupal_get_form('my_selector');
Avatar of leakim971
leakim971Flag of Guadeloupe imageMultitechnician
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers