I'm sure this is relatively easy and straightforward, but I'm having no success figuring it out.
I am trying to set the selected option of a drop down list element using the following code:
if ($(this).attr("tagName") == "SELECT") {
oldValue = $(this).parent().parent().find('span.displayField').text();
$(this).val(oldValue).attr("selected", "selected");
return;
}
But it is not changing the select element at all. The code is definitely running, and oldValue
is being populated appropriately.
Can anyone see what I might be missing?
Thanks!
UPDATE:
For clarification, here is the HTML:
<span class="displayField">Pending</span>
<span class="editField">
<select data-val="true" data-val-number="The field ProgramStatusId must be a number." data-val-required="The ProgramStatusId field is required." id="ProgramListViewModels_0__ProgramStatusId" name="ProgramListViewModels[0].ProgramStatusId">
<option value="1">Pending</option>
<option value="2">Tabled</option>
<option value="3">Approved</option>
<option value="4">Declined</option>
</select>
</span>