top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to display array to Dynamic drop down list using javascript?

+1 vote
577 views
How to display array to Dynamic drop down list using javascript?
posted Jan 28, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
<html>

<head>
<title>PING</title>

<script  language=javascript type="text/javascript">

var month = new Array("January","February","March","April","May","June",
"July","August","September","October","November","December"); 

var selObj = document.forms["drop_list"].elements["Month_list"];

for (var i=0; i < month.length;++i)
{

addOption(selObj, month[i], month[i]);
}

function addOption(selectbox,text,value )
{
document.write("ramesh");
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

</script>
</head>


<body>

<FORM name="drop_list" action="NextPage.jsp" method="POST" >

<SELECT NAME="Month_list">
<option value="" >Month list</option>
</SELECT>

</FORM>

</body> 
</html>
answer Jan 28, 2016 by Shivaranjini
Similar Questions
+2 votes

I am Getting may JSON array . But i can't know how to fill dropdown list with this array ...

<script>
  function Customer_Id()  
  {  
      var Cus_id = document.getElementById("customer").value;  
      alert(Cus_id);
      var xhr;  
      if (window.XMLHttpRequest) // Mozilla, Safari, ... 
       {   
            xhr = new XMLHttpRequest();  
       }  
        else if (window.ActiveXObject) // IE 8 and older 
        {   
            xhr = new ActiveXObject("Microsoft.XMLHTTP");  
        }  
          var data = "Customer_ID=" + Cus_id;  

             xhr.open("POST", "Volumne_WebUser.php", true);   
             xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                    
             xhr.send(data);
              xhr.onreadystatechange = display_data;  
      function display_data() {  
     if (xhr.readyState == 4) {  
      if (xhr.status == 200) {  
      var response = xhr.responseText;
      var obj = JSON.parse(response);
      alert(obj['Name']);     
      } else {  
        alert('There was a problem with the request.');          
      }  
     }  
    }  
  }
</script>
+1 vote

I have a requirement to populate the drop down list I need to load data from a database table to drop down list in java

my database table is this

CREATE TABLE CITY_MASTER_PL(
CITYID BIGINT NOT NULL,
INVENTORY_SOURCE CHAR,
CITY_NAME VARCHAR(250),
STATE_CODE VARCHAR(250),
STATE_NAME VARCHAR(250),
COUNTRY_CODE VARCHAR (250),
COUNTRY_NAME VARCHAR (250),
HOTEL_COUNT BIGINT,
LATITUDE BIGINT,
LONGITUDE BIGINT,
PRIMARY KEY (CITYID)
); 

in this table I need to load all country name state name and city name can any one help me out this thanks in advance

...