dynamic <input> tag
I have a simple form:
<form id="form" action="#">
<input type="text" id="2" name="2" size="40" onclick="alert('ok-2')"></input>
</form>
and I want to create dynamically once more <input> tag inside this form.
My problem is - after creating tag, onclick method doesn't work.
So, what I did
<form id=form action="#">
<input type="text" id="2" name="2" size="40" onclick="alert('ok-2')"></input>
</form>
<input type=button onclick=javascipt:writeline("3") value="create tag input"> </input>
<script language="JavaScript" type="text/javascript">
function writeline(str) {
var oForm = document.getElementById("form");//
var oInput = document.createElement("input");
oInput.setAttribute("type", "text");
oInput.onclick="alert('ok-3')";
oInput.id=str;
oInput.name=str;
oForm.appendChild(oInput);
}// end of writeline(str)
</script>
Any ideas?
|