For a page contains INPUT
[code]
<body>
<div id=”p”>
<input type=”text” class=”abc” id=”inp1″ name=”inp1″ value=”” maxlength=30 />
</div>
</body>
Now I want to dynamically duplicate the input field, i.e., copy all the information except the id and name, what should be the javascripts for this?
After duplicate:
[code]
<div id=”p”>
<input type=”text” class=”abc” id=”inp1″ name=”inp1″ value=”” maxlength=30 />
<input type=”text” class=”abc” id=”inp2″ name=”inp2″ value=”” maxlength=30 />
<input type=”text” class=”abc” id=”inp3″ name=”inp3″ value=”” maxlength=30 />
…
</div>
Thanks
Scott
I tried something like this:
[code]
x= document.createElement(“input”);
x.id=”inp2″;
x.name= “inp2”;
x.maxlength=document.getElementById(‘inp1’).maxlength;
x.classname=document.getElementById(‘inp1’).classname;
x.style.top=document.getElementById(‘inp1’).offsetTop + document.getElementById(‘inp1’).offsetHeight + 5;
x.style.left=document.getElementById(‘inp1’).offsetLeft;
document.getElementById(‘p’).appendChild(x);
I mean, is there a better way to do this?