[support] How to add "selected" attribute to select list <option>tag
Greg Holsclaw
Greg.Holsclaw at trouvemedia.com
Wed Nov 28 04:37:20 UTC 2007
Make the #default_value an array of the keys of the options you want
selected.
$form['item'] = array(
'#type' => 'select',
...
'#options' => array of all options,
'#default_value' => array of keys from above options.
...
);
Check
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html
/5#default_value for more info.
Greg
-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Steve Edwards
Sent: Tuesday, November 27, 2007 8:25 PM
To: support at drupal.org
Subject: [support] How to add "selected" attribute to select list
<option>tag
Well, I'm back again, and this time I have a question about attributes
for select options in a form. I have a form that has a
select element (multi-select) that lists users. The form is for some
admin settings for a module. When the form is displayed, I
need to be able to highlight specific options in the list based on data
returned from a query. I've been looking all day, and
haven't been able to figure it out. There is the #attribute key, but it
is for the field as whole (at least as far as I can
determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
--
[ Drupal support list | http://lists.drupal.org/ ]
More information about the support
mailing list