Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript create form element

<script>
            var down = document.getElementById("GFG_DOWN");
            function GFG_Fun() {
               
                // Create a form dynamically
                var form = document.createElement("form");
                form.setAttribute("method", "post");
                form.setAttribute("action", "submit.php");
 
                // Create an input element for emailID
                var ID = document.createElement("input");
                ID.setAttribute("type", "text");
                ID.setAttribute("name", "emailID");
                ID.setAttribute("placeholder", "E-Mail ID");
 
                // Create an input element for password
                var PWD = document.createElement("input");
                PWD.setAttribute("type", "password");
                PWD.setAttribute("name", "password");
                PWD.setAttribute("placeholder", "Password");
 
                // Create a submit button
                var s = document.createElement("input");
                s.setAttribute("type", "submit");
                s.setAttribute("value", "Submit");
 
                // Append the email_ID input to the form
                form.append(ID);
               
                // Append the password to the form
                form.append(PWD);
               
                // Append the button to the form
                form.append(s);
 
                document.getElementsByTagName("body")[0]
               .appendChild(form);
            }
</script>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #javascript #create #form #element
ADD COMMENT
Topic
Name
2+5 =