I have got a Html form with a table.
The table contains textfield and a button.
When I click the button I want another textfiled to be created.
(I have done till here)
The problem is that I want the new textfield to be created in the same cell (within <TD> tag) where the first textfield is. I have tried to use <span> tag so as to force the new textfield to be created in the table cell. But I could not succeed.
My code goes as follows:
<html>
<head>
<title>testin g</title>
<script type="text/javascript">
var counter = 0;
function createTextField (name, id, parentEl) {
if(navigator.us erAgent.toLower Case().indexOf( "msie") != -1) { isIE = true; } else { isIE = false; }
if(isIE) {
newInput = document.create Element('<INPUT name=\''+(name+ counter)+'\'>') ;
} else {
newInput = document.create Element('INPUT' );
newInput.name = name + counter;
newInput.size = 10;
}
newInput.type = 'text';
newInput.id = id + counter;
if(parentEl && parentEl != "") {
if(typeof(paren tEl) == "string") {
parentEl = document.getEle mentById(parent El);
}
parentEl.append Child(newInput) ;
parentEl.append Child(document. createElement(' BR')); // break line
} else {
document.body.a ppendChild(newI nput);
document.body.a ppendChild(docu ment.createElem ent('BR')); // break line
}
counter++;
}
</script>
</head>
<body>
<table>
<tr>
<td><input type="text" name="username" id="user" size="20" value="" /><span id="putInputEle mentsHere"></span></td>
<td><input type="button" value="More" onClick="create TextField('myIn put', 'myInputId', '');" /></td>
</tr>
</table>
<p> </p>
</body>
</html>
The table contains textfield and a button.
When I click the button I want another textfiled to be created.
(I have done till here)
The problem is that I want the new textfield to be created in the same cell (within <TD> tag) where the first textfield is. I have tried to use <span> tag so as to force the new textfield to be created in the table cell. But I could not succeed.
My code goes as follows:
<html>
<head>
<title>testin g</title>
<script type="text/javascript">
var counter = 0;
function createTextField (name, id, parentEl) {
if(navigator.us erAgent.toLower Case().indexOf( "msie") != -1) { isIE = true; } else { isIE = false; }
if(isIE) {
newInput = document.create Element('<INPUT name=\''+(name+ counter)+'\'>') ;
} else {
newInput = document.create Element('INPUT' );
newInput.name = name + counter;
newInput.size = 10;
}
newInput.type = 'text';
newInput.id = id + counter;
if(parentEl && parentEl != "") {
if(typeof(paren tEl) == "string") {
parentEl = document.getEle mentById(parent El);
}
parentEl.append Child(newInput) ;
parentEl.append Child(document. createElement(' BR')); // break line
} else {
document.body.a ppendChild(newI nput);
document.body.a ppendChild(docu ment.createElem ent('BR')); // break line
}
counter++;
}
</script>
</head>
<body>
<table>
<tr>
<td><input type="text" name="username" id="user" size="20" value="" /><span id="putInputEle mentsHere"></span></td>
<td><input type="button" value="More" onClick="create TextField('myIn put', 'myInputId', '');" /></td>
</tr>
</table>
<p> </p>
</body>
</html>
Comment