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');

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros