Add Array element to Select Option - Javascript jQuery

Javascript examples for jQuery:Array

Description

Add Array element to Select Option

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from  ww w . j a  v  a2s .c  om*/
var selectList = {};
selectList[1] = "AAA";
selectList[2] = "BBB";
$.each(selectList, function (key, value) {
    $('#my').append($("<option/>", {
        value: key,
        text: value
    }));
});
    });

      </script> 
 </head> 
 <body> 
  <select id="my"></select>  
 </body>
</html>

Related Tutorials