add() Method
The add() method is used to add an option in a drop-down list.
This simplifies the work of user whenever it is required to add element or option.
below is the example of add() method which is used in dropdown menu and gives the idea how to use it while working in javascript.
<!DOCTYPE html>
<html>
<body>
<form>
<select id="mySelect">
<option>Date</option>
</select>
</form>
<br>
<script>
window.onload=function myFunction() { /* window.onload Execute a JavaScript immediately after a page is loaded*/
for(var i=1;i<31;i++){
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = i;
x.add(option,i);
}}
</script>
</body>
</html>
0 Comment(s)