Answers.Body: <pre><code>$this-&gt;add('select', 'financial_type', ts('Financial Type'), 
              $financialTypes, 
              'TRUE'
              )-&gt;setSelected(9);
  </code></pre>
  
  <p>You can set selected item directly this way.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-06T07:11:04.937Z
Answers.LastActivityDate: 2019-09-06T07:11:04.937Z
Answers.UserDisplayName: pdchaudhary
Answers.Body: <p>This is how you do it:</p>
  
  <pre><code>CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
      $this-&gt;add('select', 'financial_type', ts('Financial Type'), 
              $financialTypes, 
              'TRUE'
              );
      $this-&gt;_elements[4]-&gt;setSelected(9);
  </code></pre>
  
  <p>You need to inspect $this and determine which of the elements is the select you want to modify. In my case it was the 4th one. </p>
  
  <p>You then need to inspect the select (from the browser) and find out the value for the option that you want selected by default. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-13T15:50:42.563Z
Answers.LastActivityDate: 2016-07-13T15:50:42.563Z
Answers.UserDisplayName: Sleewok
Body: <p>Maybe is a simple question but, in my form, I not able to set the "selected" value, in my SELECT element:
  The following is my code:</p>
  
  <pre><code>CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
  $this-&gt;add('select', 'financial_type', ts('Financial Type'), $financialTypes, 'TRUE');
  </code></pre>
  
Tags: <quickform>
Title: Quickform: Set the "Selected" value in a select element
ThreadText: # Quickform: Set the "Selected" value in a select element
  
  (Asked by: username_0 on 2016-05-18)
  
  Maybe is a simple question but, in my form, I not able to set the "selected" value, in my SELECT element:
  The following is my code:
  
  ```
  CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
  $this->add('select', 'financial_type', ts('Financial Type'), $financialTypes, 'TRUE');
  
  ```
  
  **Tags:** quickform
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-07-13. Score: 3 | Accepted answer
  
  This is how you do it:
  
  ```
  CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
      $this->add('select', 'financial_type', ts('Financial Type'), 
              $financialTypes, 
              'TRUE'
              );
      $this->_elements[4]->setSelected(9);
  
  ```
  
  You need to inspect $this and determine which of the elements is the select you want to modify. In my case it was the 4th one.
  
  You then need to inspect the select (from the browser) and find out the value for the option that you want selected by default.
  
  
  ---
  
  ### Answer by username_1 on 2019-09-06. Score: 0
  
  ```
  $this->add('select', 'financial_type', ts('Financial Type'), 
              $financialTypes, 
              'TRUE'
              )->setSelected(9);
  
  ```
  
  You can set selected item directly this way.
  
  
  ---
  
  