dynamic - A button that when clicked will generate a new textbox? - Javascript -
so, have 3 textboxes. first asks first name, second last name, , third age.
when click button, fourth textbox should generated , should contain entered in each textbox far. problem can't fourth textbox appear. feel i'm missing that's pretty simple. here code far.
<html> <head> </head> <body> <script> function addtextbox() { var element = document.createelement("input"); element.setattribute("type", "text"); element.setattribute("value", ""); element.setattribute("name", "test name"); } </script> <form> <input type="text" value="firstname"> <input type="text" value="lastname"> <input type="text" value="age"> <input type="button" onclick="addtextbox()"> </form> </body> </html>
you need append element in body using appendchild whereas have created element missed add in document
function addtextbox() { var element = document.createelement("input"); element.setattribute("type", "text"); element.setattribute("value", ""); element.setattribute("name", "test name"); document.body.appendchild(element); }
Comments
Post a Comment