Set Id to select options. (Drop Down Element Id's)

Set Id to select options. (Drop Down Element Id's)

daniegloydaniegloy Posts: 35Questions: 12Answers: 5

Hi, I have a dynamic drop down list being populated from a query. I am struggling to find a way to assign id='' to each option element. When an item is selected i need to use $(#+'the selected id').on('click' to preform a function. How do i assign id's to the option elements.
'''js

  aStateList[x] = { 'label': '+YdataArray[x]['RegYear']+'', 'value':'+YdataArray[x]['RegYear']+'','Id':''+YdataArray[x]['RegYear']};

                 $('#'+YdataArray[x]['RegYear']).on('click', function(){
                                         //  console.log('Selected');
                 })

                  }

'''

This question has accepted answers - jump to:

Answers

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5
    Answer ✓
      $('select',editorNewForm.field('YEAR').node()).on('click',function () {
          console.log($(this).val());
    
    
    
        });
    

    This Worked For me.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    That looks correct. The other way to get the select element is via the field().input() method.

    Allan

This discussion has been closed.