title: Set Dropdownlist selected index with javascript?
body: <p>I have 2 dropdownlists on a asp page.</p>
  
  <p>If user changes the selected index of the first drop down list, then set <code>DDL2.selectedindex = DDL1.Selectedindex</code></p>
  
  <p>and do this same logic except switch DDL1 and DDL2 respectively. I have these both getting populated from the same list of objects(just different properties set to each) and i have a order by clause on the query to ensure the data stays in sync. My question is how can i get this logic to work in javascript? My current method is as such..</p>
  
  <pre><code>Accounts.Attributes.Add("onBlur", Customers.SelectedIndex = Accounts.SelectedIndex)
  Customers.Attributes.Add("onBlur", Accounts.SelectedIndex = Customers.SelectedIndex)
  </code></pre>
  
  <p>This code doesn't work but demonstrates what im shooting for. When the ddl getting the first selection loses focus, populate the other ddl(setting the selected index). Any help would be great!</p>
  
  <hr>
  
  <p>Can someone see what i'm doing wrong here?</p>
  
  <pre><code>            $("[id$=ddlStandardAcctNo]").change(function () {
  
              var acc = $("[id$=ddlStandardAcctNo]");
              var cust = $("[id$=ddlCustomerName]");
              cust.selectedindex = acc.selectedindex;
          });
  </code></pre>
  
  <p>It compiles and just doesn't work... :( These drop downs are inside of a asp gridview.</p>
  
  <hr>
  
  <p>After looking at that i'm trying to do this..</p>
  
  <pre><code>        $("[id$=ddlStandardAcctNo]").blur(function () {
  
          var acc = document.getElementById('&lt;%=ddlStandardAcctNo.ClientID %&gt;');
          var cust = document.getElementById('&lt;%=ddlCustomerName.ClientID %&gt;');
          cust.selectedindex = acc.selectedindex
      });
  
      $("[id$=ddlCustomerName]").blur(function () {
  
          var acc = document.getElementById('&lt;%=ddlStandardAcctNo.ClientID %&gt;');
          var cust = document.getElementById('&lt;%=ddlCustomerName.ClientID %&gt;');
          acc.selectedindex = cust.selectedindex
      });
  </code></pre>
  
  <p>Problem is i never use document.ready cause the dropdownlist are in a gridview. I'm literally just learning javascript/jquery as i run across issues like this so feel free to crack the knowledge whip lol. </p>