Showing posts with label dropdown list. Show all posts
Showing posts with label dropdown list. Show all posts

Wednesday, November 21, 2018

Get the dropdown list value and list in JQuery





I have a dropdown list class TaList in a column in a table.
To get the option value of dropdown list in JQuery:
  row3.find('td.TaList select').val();
To get the selected text of dropdown list in JQuery:
  stakeholder_name1 = row3.find('td.TaList :selected').text();
More codes:
$('div.ajax_list').find("#defaultTable").find('tr').each(function() {
    if($(this).find('.swap_option').attr('checked') == 'checked') total += 1;
    var row3=  $(this);
    if(total==1 && $(this).find('.swap_option').attr('checked') == 'checked'){
        courses_offered_id1=row3.find("input.courses_offered_id").val();
        stakeholder_id1 = row3.find('td.TaList select').val();
        stakeholder_name1 = row3.find('td.TaList :selected').text();
        section1 = row3.find('.TutSection').html();
        assignedID1 = row3.find('.assignedID').val();
    }
    if(total==2 &&$(this).find('.swap_option').attr('checked') == 'checked'){
        courses_offered_id2=row3.find("input.courses_offered_id").val();
        stakeholder_id2 = row3.find('td.TaList select').val(); 
        assignedID2 = row3.find('.assignedID').val();
        stakeholder_name2 = row3.find('td.TaList :selected').text();
        section2 = row3.find('.TutSection').html();               
    }           
});