I am trying to show the selected value of a drop down, but its not selected the dropdown value, but adding another value to the dropdown list.
here is the code I am using:
jquery
var companyId = $(this).closest('tr').find('#headquarterIdForSearch').text();
var companyName = $(this).closest('tr').find('#companyNameId').text();
$(this).parents().find('.hqSelect option:selected').val(companyId).text(companyName);
The above code is not selecting the value that I am assigning to the Text and val property. However, it is adding a new property. Lets say, I have fetched value for companyName as "FIS" and companyId as 123.
The value is present under the dropdown however, it is adding a new value to the dropdown.
How can I show the selected value? I have also used the below code:
$('#dropDownId :selected').text();
Thanks,