This code adds two more items to the dropdown when run. (text1 and text2). The opposite coding is here (Remove)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php echo '<label for="dropdown1">Select Dropdown Choice:</label> <select name="dropdown1" id="dropdown1"> <option value="Choice1">Choice 1</option> <option value="Choice2">Choice 2</option> <option value="Choice3">Choice 3</option> </select>'; ?> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ var myOptions = { val1 : 'text1', val2 : 'text2' }; $.each(myOptions, function(val, text) { $('#dropdown1').append( new Option(text,val) ); }); }); </script> |