I am trying to dynamically create input tag and then embed it in the form element but this code doesnt work , i cant figure out why . Please help me . <html> <head> <script type="text/javascript"> function create_input() { alert("random"); var itag = document.createElement("input"); itag.setAttribute("name","1"); itag.setAttribute("type","text"); var ftag = document.getElementById("form1"); document.ftag.appendChild(itag); } </script> </head> <body> <form id="form1"> <input type="BUTTON" value="create input" onclick="create_input()"> </form> </body> </html> Code (markup): Thanks in advance
Yes, I believe so. You don't need to use document. prefix anymore because you already have the reference of form1 by using document.getElementById("form1"). Try it.