Is it possible to have a select list with an option for 'Other' (or whatever else) that displays a textbox the contents of which is saved as the value if 'Other' is selected?

I've tried this sort of thing:

$form['options'] = array(
    '#type' => 'select',
    '#title' => t('Select some options'),
    '#default_value' => $node->options,
    '#options' => array(
      'Option 1' => 'Option one!!',
      'Option 2' => 'This is the second option.',
      'Other' => array(
          '#type' => 'textfield',
          '#title' => t('Other'),
      )
);

...but it doesn't work. Is there a way of making this happen?

Comments

JmsCrk’s picture

Hmm. No comments, I guess that means it can't be done.

An alternative solutionmight be to have separate form items but use some javascript to hide and display them based on selections from the first drop-down - sounds doable but I'm not really great with javascript even outside of form api. Any ideas on how I might achieve this?

| websites | drupal | marketing || chocchip.com.au |

JmsCrk’s picture

Just for anyone else who stumbles across tihs: I managed to get the sort of right thing happening by having the 'Other' text field and using the dependent module to show/hide it depending on selected choice in a dropdown.

| websites | drupal | marketing || chocchip.com.au |