Krit Krit - 4 months ago 9
HTML Question

Creating Dynamic Textbox , but code not working

I have just started learning java script.I am trying to make Dynamic text box but the my code is not working . Can someone help me in rectifying my mistake??

<html>
<head>
</head>
<body>
<script language="javascript">

function add(){
var text=document.createElement('input');
var add=document.getElementById("Myform");
text.setAttribute("type","text");
text.setAttribute("name","BookName");
add.appendChild(text);
}
</script>
<form action="new1.php" id="Myform">
<input type="submit" value="Submit" id="submit" onclick="javascript:add();"/> <br/>

</form>
</body>
</html>


The text box disappears before I can do anything with it.

Answer

Change the input type as button or other wise it will submit the form.You want the submit button means you have to add one more button for dynamic action.

<input type="button" value="Submit" id="submit" onclick="javascript:add();"/> 
Comments