Question

I need to run a function for each item in a drop down menu. The code is:

    $( document ).ready(function() {
     $('[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"]')
            .each(function(index) {
/* here, I need to do some manipulation on the item */
                  console.log("index is:"+???+"value is"+???);
            });

    });

I understand that i need to put something before each() to select all items but I don't know what to put

Thank you

The drop down menu is :
<select id="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b_$LookupField" title="Εισ. Δικηγόρος/οι">
<option value="0">(None)</option> <option value="1">(Name1)</option>  etc
Was it helpful?

Solution

Try this:

$(document).ready(function(){
    $('select[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"] option').each(function(index,value) {
        console.log("index is:"+index); // index
        console.log("value is"+$(this).val()); // dropdown option value
        console.log("dropdown text value is"+$(this).text()); //dropdown option text
    });
});

DEMO

OTHER TIPS

.each(index, value) //2 parameter with index as well as value

In your case value returns the htmlElement as object so use $(this).val()

so you can have

$('[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"]
         > option').
            .each(function(index, value) {
      console.log("index is:"+index+"value is"+$(this).val());

I think that It will help you.

$("#dropdownid option").each(function(){
  /* write code what ever you want to do */
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top