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>

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Shallow Copy Deep Copy Java example

Database Connection using NODE JS example