make drop down list in javascript example
Make dynamic drop down list in java script.
<html>
<head>
<script>
function makeDropDown(){
var formDiv = document.getElementById("div");
var selectTag=document.createElement("select");
selectTag.appendChild(getOption("First Value", "First Text"));
selectTag.appendChild(getOption("Second Value", "Second Text"));
formDiv.appendChild(selectTag);
}
function getOption(value, text){
var optionTag = document.createElement("option");
var text = document.createTextNode(text);
optionTag.setAttribute("value", value);
optionTag.appendChild(text);
return optionTag;
}
</script>
</head>
<body onload="makeDropDown()">
<div id="div"></div>
</body>
</html>
<html>
<head>
<script>
function makeDropDown(){
var formDiv = document.getElementById("div");
var selectTag=document.createElement("select");
selectTag.appendChild(getOption("First Value", "First Text"));
selectTag.appendChild(getOption("Second Value", "Second Text"));
formDiv.appendChild(selectTag);
}
function getOption(value, text){
var optionTag = document.createElement("option");
var text = document.createTextNode(text);
optionTag.setAttribute("value", value);
optionTag.appendChild(text);
return optionTag;
}
</script>
</head>
<body onload="makeDropDown()">
<div id="div"></div>
</body>
</html>
Comments
Post a Comment