Dynamically Populating Select Control
Hi,
I have found problems with dynamically populating a select control, the simple logic I use works fine in standard JQuery but not in JQueryMobile. The code is as follows:
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Select Test</title>
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css"/>
- <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function init()
- {
- console.log("init");
- var options='<option value="1">Test 2</option>';
- $("select#select-choice-1").append(options);
- });
- </script>
- </head>
- <body>
- <div data-role="page" data-theme="b" id="jqm-home">
- <div data-role="content">
- <div data-role="fieldcontain">
- <label for="select-choice-1" class="select">Choose:</label>
- <select name="select-choice-1" id="select-choice-1">
- <option value="0">Test 1</option>
- </select>
- </div>
- </div>
- </body>
- </html>
What happens is (1) the select only populates with the single 'test 1' option value (2) on first click of the select this single option (still only one option) is displayed as per usual with JQueryMobile (3) on select of this 'test 1' option the select then loses its selected option rendering the select empty (4) on third click of the select control it then re-displays the option list but this time correctly showing both options?