[SalesForce] Get selected value of picklist in javascript

I have a selectlist in my apex:repeat. On click of command button i want to get the selected values in all the rows in my js function. My code:

    <apex:repeat value="{!myWrapper}" var="wrap">
    <tr>

     <td>
     <apex:selectList 
    id="selected" value="{!wrap.selected}" size="1"   style="width: 100%;" >

    <apex:selectOptions value="{!wrap.SelectList}">
    </apex:selectOptions>
      </apex:selectList>
    </td>
    </tr>
    </apex:repeat>
     <apex:commandButton onclick="if(!fncInitiate()){return false};return 
false;" value="Perfios Initiate - Applicant" style="width:19%;color: #0072bc;" reRender=""/>

js:

function fncInitiate(){
 //get the selected value from all the rows here
}                                                      

Best Answer

Define a Id on tag in your visualforce page

<apex:repeat value="{!myWrapper}" var="wrap">
<tr>

 <td id="SelectedComponent">
 <apex:selectList 
id="selected" value="{!wrap.selected}" size="1"   style="width: 100%;" >

<apex:selectOptions value="{!wrap.SelectList}">
</apex:selectOptions>
  </apex:selectList>
</td>
</tr>
</apex:repeat>
 <apex:commandButton onclick="if(!fncInitiate()){return false};return 
false;" value="Perfios Initiate - Applicant" style="width:19%;color: #0072bc;" reRender=""/>

Then get the selected value in the javaScript method through the help of this Id.

JS:-

function fncInitiate(){
//get the selected value from all the rows here
var selectedValue = $("#SelectedComponent").find(":selected").text();
console.log(selectedValue);
}