I am attempting to retrieve and set the selected value of a select element (drop down list) with jQuery.
for retrievel i have tried $(\"#myId\").find(\':select
$('#myId').val()
should do it, failing that I would try:
$('#myId option:selected').val()
I know this is old but I just had a bear of a time with Razor, could not get it to work no matter how hard I tried. Kept coming back as "undefined" no matter if I used "text" or "html" for attribute. Finally I added "data-value" attribute to the option and it read that just fine.
<option value="1" data-value="MyText">MyText</option>
var DisplayText = $(this).find("option:selected").attr("data-value");
When setting with JQM
, don't forget to update the UI
:
$('#selectId').val('newValue').selectmenu('refresh', true);