title: Pentaho - how to get the index of selected component?
body: <p>I'm trying to get the index of a selected element using <code>Select Component</code> in <code>CDE Dashboard</code>.</p>
  
  <p>It's very easy:</p>
  
  <pre><code>SELECT id, username FROM table1      
  -- this feeds the Select Component
  </code></pre>
  
  <p>I have "Value as ID" set to <code>FALSE</code>, so the dropdown will show the <code>username</code> and will return the <code>ID</code> as defined in the <code>Parameter</code> field of <code>Select Component</code>.</p>
  
  <p>I need to write some JavaScript code to read both values (<code>ID</code> and <code>username</code>) from the selected option and I have tried it with <code>this.selectedIndex</code>, but it always returns <code>-1</code>.</p>
  
  <p>If I can get the index, I could iterate over the <code>resultSet</code> object and get all the columns.</p>
  
  <p>Also tried with JQuery, but I'm not an expert, though I gave it a try with:</p>
  
  <pre><code>$( "#my_select_component" ).val()
  </code></pre>
  
  <p>and it didn't work.</p>
  
  <p>If there is an easier way to achieve this, I would highly appreciate it and give feedback.</p>