psim
Feb 24th 2009, 1:28 pm
hello all,
i thought not to paste my code...only to paste the exact part in whick i need help..
i am very confused...read comments to understand what exactly i want to do...
i want to create with innerhtml a input text and a button...and with that button to create also with innerhtml another element, for example an input textarea..
please help its very important for me...
<script>
function addfield() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<input type=\"text\" name=\"firstname\"><INPUT type=\"button\" name=\"addfield\" value=\"add!\ onclick=\"addfield(XXXXX)\">";
/*i want the value in addfield to be unique for a specific "my"+num+"Div" so for every field a create to be able to create as many subfields as i want..for example i want this...
create my1div then press add! and create for example my1.1div press again and create my1.2div
create my2div
create my3div then press add! and create for example my3.1div press again and create my3.2div
*/
ni.appendChild(newdiv);
}
function addsubfield(){//here i want to create <input type=\"text\" name=\"something else\">
XXXXXXXXX
}
</script>
<body>
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addfield();">Add Some Elements</a></p>
<div id="myDiv"> </div>
</body>
i thought not to paste my code...only to paste the exact part in whick i need help..
i am very confused...read comments to understand what exactly i want to do...
i want to create with innerhtml a input text and a button...and with that button to create also with innerhtml another element, for example an input textarea..
please help its very important for me...
<script>
function addfield() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<input type=\"text\" name=\"firstname\"><INPUT type=\"button\" name=\"addfield\" value=\"add!\ onclick=\"addfield(XXXXX)\">";
/*i want the value in addfield to be unique for a specific "my"+num+"Div" so for every field a create to be able to create as many subfields as i want..for example i want this...
create my1div then press add! and create for example my1.1div press again and create my1.2div
create my2div
create my3div then press add! and create for example my3.1div press again and create my3.2div
*/
ni.appendChild(newdiv);
}
function addsubfield(){//here i want to create <input type=\"text\" name=\"something else\">
XXXXXXXXX
}
</script>
<body>
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addfield();">Add Some Elements</a></p>
<div id="myDiv"> </div>
</body>