Reputation: 4187
I have some date and time pickers in a form using dropdowns.
I am able to pre-select the current day, month etc using the following:
var d = new Date();
var day = d.getDate();
var month = d.getMonth()+1;
var year = d.getYear();
$('#day option[value=' + day + ']').attr('selected',true);
$('#month option[value=' + month + ']').attr('selected',true);
$('#year option[value=' + year + ']').attr('selected',true);
This is initialised using:
$('#page-id').bind('pageinit', function(event) {...});
When I view the page source, the correct option is selected, how ever, the select dropdown just shows the first option e.g. todays date, the 14th, is selected, but the actual dropdown says the 1st.
Clicking the dropdown and re-selecting the current date, the selection still does't change!
I have to select a different day and re-select the current day to get the option to change on the view.
I ran a jsFiddle, and that worked perfectly - http://jsfiddle.net/3aRgR/
Upvotes: 1
Views: 1843
Reputation: 4187
Nevermind, I found it in the Official Docs! You have to do:
$('#day').selectmenu('refresh');
Upvotes: 1
Reputation: 3169
You must have 2 options selected. Try to unselect first or try this that is more readable:
$('#day').val(day);
Upvotes: 0