title: how can I select a default option in a dropdown list?
body: <p>I have this JS file, by default i want to make an option selected . I mean, i want to make selected the Country "<code>USA</code>" with the value "<code>USA</code>" .<br>
  This is what i have by default :</p>
  
  <p><img src="https://i.stack.imgur.com/TB4WK.png" alt="enter image description here"></p>
  
  <p>This is the JS file :</p>
  
  <pre><code>var town_country_arr = new Array("Canada", "USA");    
      var s_a = new Array();        
      s_a[0]="";        
      s_a[1]="Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland|Northwest Territories|Nova Scotia|Nunavut|Ontario|Prince Edward Island|Quebec|Saskatchewan|Yukon Territory";
  
      s_a[2]="Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming";
  
      function print_town_country(town_country_id){        
          // given the id of the &lt;select&gt; tag as function argument, it inserts &lt;option&gt; tags        
          var option_str = document.getElementById(town_country_id);        
          option_str.length=0;        
          option_str.options[0] = new Option('Pays','');        
          option_str.selectedIndex = 0;        
          for (var i=0; i&lt;town_country_arr.length; i++) {        
              option_str.options[option_str.length] = new Option(town_country_arr[i],town_country_arr[i]);
  
          }
  
      }
  </code></pre>
  
  <p>EDIT : My view in Cake</p>
  
  <pre><code>&lt;div class="form-group"&gt;
                            &lt;div class="col-xs-6"&gt;
                              &lt;?php echo $this-&gt;Form-&gt;input('country', array('type' =&gt; 'select', 'class' =&gt; 'form-control', 'label' =&gt; 'Pays', 'id' =&gt; 'town_country', 'onchange' =&gt; "print_state('state',this.selectedIndex);", 'selected' =&gt; $selectedcountry, 'empty' =&gt; 'Pays')); ?&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
  
                        &lt;div class="form-group"&gt;
                            &lt;div class="col-xs-6"&gt;
                        &lt;?php 
                        echo $this-&gt;Form-&gt;input('localisation', array('type' =&gt; 'select', 'class' =&gt; 'form-control', 'label' =&gt; 'Localisation', 'id' =&gt; 'state', 'empty' =&gt; $namelocalisation,
                              'options' =&gt; $localisations)); ?&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;  
  
                        &lt;script language="javascript"&gt;print_town_country("town_country");&lt;/script&gt;    
  </code></pre>
  
  <p>the variable selectedcountry equal USA ...</p>
  
  <p>With Firebug :</p>
  
  <pre><code>&lt;div class="col-xs-6"&gt;
  &lt;div class="input select required"&gt;
  &lt;label for="town_country"&gt;Pays&lt;/label&gt;
  &lt;select id="town_country" class="form-control" onchange="print_state('state',this.selectedIndex);" name="data[Town][country]"&gt;
  &lt;option value=""&gt;Pays&lt;/option&gt;
  &lt;option value="Canada"&gt;Canada&lt;/option&gt;
  &lt;option value="USA"&gt;USA&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>