<DIV>Hi Steve,</DIV>
<DIV> </DIV>
<DIV>I just tested the code in firefox and it works. Maybe it is a browser compliancy issue? </DIV>
<DIV> </DIV>
<DIV>Two of the names are displayed as selected initially.</DIV>
<DIV> </DIV>
<DIV>Sarah<BR>----- Original Message -----<BR>From: Steve Edwards <killshot91@comcast.net><BR>Date: Wednesday, November 28, 2007 3:19 pm<BR>Subject: [support] [Fwd: Re: How to add "selected" attribute to select list <option>tag]<BR>To: support@drupal.org<BR><BR>> I guess I spoke too soon. I did it as an array<BR>> <BR>> #default_value => array(2,3)<BR>> <BR>> and upon viewing the source, I discovered that it adds the <BR>> selected="selected" attribute to my option tags like I <BR>> want. The <BR>> problem is, the items aren't being highlighted on the screen.<BR>> <BR>> so this code:<BR>> <BR>> *<BR>> * Define the project permissions settings form<BR>> */<BR>> function project_permissions_form($project_nid, $project_name) {<BR>> $form['#base'] = 'project_permissions_form';<BR>> <BR>> $form[$project_nid] = array(<BR>> '#type' => 'fieldset',<BR>> '#title' => $project_name,<BR>> '#collapsible' => TRUE,<BR>> '#collapsed' => FALSE,<BR>> );<BR>> <BR>> $form[$project_nid]['projects'] = array(<BR>> '#type' => 'textfield',<BR>> '#title' => t('Project name'),<BR>> '#maxlength' => 30,<BR>> '#size' => 30,<BR>> '#default_value' => $project_name,<BR>> );<BR>> <BR>> $form[$project_nid]['users'] = array(<BR>> '#type' => 'select',<BR>> '#title' => t('Users with access to <BR>> project'), '#description' => t('Select <BR>> users to be asssigned to the project'),<BR>> '#options' => _get_user_list(),<BR>> '#multiple' => TRUE,<BR>> '#default_value' => array(2,3),<BR>> );<BR>> <BR>> $form[$project_nid]['nid'] = array(<BR>> '#type' => 'hidden',<BR>> '#value'=> $project_nid,<BR>> );<BR>> <BR>> $form[$project_nid]['submit'] = array(<BR>> '#type' => 'submit',<BR>> '#value' => 'Submit'<BR>> );<BR>> return $form;<BR>> }<BR>> <BR>> <BR>> gives me this HTML:<BR>> <BR>> <div class="form-item"><BR>> <label for="edit-users">Users with access to project: <BR>> </label> <select name="users[]" <BR>> multiple="multiple" class="form-select" id="edit-users" <BR>> ><option value="1">admin</option><option <BR>> value="2" selected="selected">bwald</option><option <BR>> value="3" selected="selected">testuser</option><option <BR>> value="4">Brian</option><option <BR>> value="5">NickH</option></select><BR>> <div class="description">Select users to be asssigned <BR>> to the project</div><BR>> </div><BR>> <BR>> So why wouldn't the items be highlighted on the screen?<BR>> <BR>> Steve<BR>> <BR>> -------- Original Message --------<BR>> Subject: Re: [support] How to add "selected" attribute to select <BR>> list <option>tagDate: Tue, 27 Nov 2007 21:04:32 -0800<BR>> From: Steve Edwards <killshot91@comcast.net><BR>> To: support@drupal.org<BR>> References: <474CED98.8090201@comcast.net> <BR>> <AF8E53B658278947AA3E09E48EF4EDAC3D73A3@TRV1DMC00.TRV.local><BR>> Hmmm, getting closer, but I can't seem to get it to work. <BR>> No matter what I try, I can't get it to select anything.<BR>> <BR>> Here is what my select list looks like (in HTML)<BR>> <BR>> <option value="1">Name 1<BR>> <option value="2">Name 2<BR>> <option value="3">Name 3<BR>> <option value="4">Name 4<BR>> <option value="5">Name 5<BR>> <BR>> The value is the user's uid. number That being the case, what <BR>> would i use for #default_value? I've tried things like<BR>> <BR>> '#default_value' => array(1 => 'Name 1')<BR>> '#default_value' => 1<BR>> '#default_value' => 'Name 1'<BR>> <BR>> but I can't get any of them to work. Any ideas?<BR>> <BR>> Thanks.<BR>> <BR>> Steve<BR>> <BR>> <BR>> Greg Holsclaw wrote:<BR>> > Make the #default_value an array of the keys of the options <BR>> you want<BR>> > selected.<BR>> > <BR>> > $form['item'] = array(<BR>> > '#type' => 'select',<BR>> > ...<BR>> > '#options' => array of all options,<BR>> > '#default_value' => array of keys from above options.<BR>> > ...<BR>> > );<BR>> > <BR>> > Check<BR>> > <BR>> http://api.drupal.org/api/file/developer/topics/forms_api_reference.html> /5#default_value for more info.<BR>> > <BR>> > Greg<BR>> > <BR>> > <BR>> > -----Original Message-----<BR>> > From: support-bounces@drupal.org [mailto:support-<BR>> bounces@drupal.org] On<BR>> > Behalf Of Steve Edwards<BR>> > Sent: Tuesday, November 27, 2007 8:25 PM<BR>> > To: support@drupal.org<BR>> > Subject: [support] How to add "selected" attribute to select list<BR>> > <option>tag<BR>> > <BR>> > Well, I'm back again, and this time I have a question about <BR>> attributes> for select options in a form. I have a form <BR>> that has a <BR>> > select element (multi-select) that lists users. The form <BR>> is for some<BR>> > admin settings for a module. When the form is displayed, <BR>> I <BR>> > need to be able to highlight specific options in the list <BR>> based on data<BR>> > returned from a query. I've been looking all day, and <BR>> > haven't been able to figure it out. There is the <BR>> #attribute key, but it<BR>> > is for the field as whole (at least as far as I can <BR>> > determine), and doesn't work for each individual <option> tag.<BR>> > <BR>> > If anybody could point me in the right direction, I would <BR>> appreciate it.<BR>> > <BR>> > Thanks.<BR>> > <BR>> > Steve<BR>> <BR>> -- <BR>> [ Drupal support list | http://lists.drupal.org/ ]<BR>> </DIV><BR><BR>Research Computing Services
<br>Sarah.Vardy@student.griffith.edu.au
<br>0402241794</BR></BR>