Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • add() method in Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 107
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: