I'm trying to add Textarea in a table cell using JavaScript, but I'm unable to do so in Firefox and Chrome. The textarea gets added in IE but not in Firefox or Chrome, in firefox and chrome the textarea appears for flash and then disappears. One more problem is if I refresh the page in IE the text in the textarea does not go, it is present even after I refresh the page. It's a very basic JavaScript function but I am not able to debug the problem. Here is the function:-
function addRow()
{
alert("height : 42px; width : 496px;");
var table = document.getElementById('tableId');
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var textNode = document.createTextNode(rowCount + 1);
cell1.appendChild(textNode);
Thank you for an early response. I tried running the script but it still does not create the textarea. textarea element gets created and disappears with a flash. Why can't we create a textarea using document.createelement(elementName) instead of --document.createElement('<'+tag+(type?' type='+type:'')+' name='+nme+' >');-- Did we miss passing type as a parameter? in the method call :- `var textArea = zxcFormField('TEXTAREA','option1');`
What does type mean in the method parameter here? and why does the element disappear as it get's created?
My whole JavaScript now looks like this:-
function addRow()
{
alert("height : 42px; width : 496px;");
var table = document.getElementById('tableId');
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var textNode = document.createTextNode(rowCount + 1);
cell1.appendChild(textNode);
var cell2 = row.insertCell(1);
var textArea = zxcFormField('TEXTAREA','option1');
textArea.setAttribute("name","option1");
textArea.setAttribute("cols","20");
textArea.style.height = "42px";
textArea.style.width = "496px";
cell2.appendChild(textArea);
}
function zxcFormField(tag,nme,type){
var el;
try {
el=document.createElement('<'+tag+(type?' type='+type:'')+' name='+nme+' >');
}
catch (e){
el=document.createElement(tag);
if (type) el.type=type;
el.name=nme;
}
return el;
}
Bookmarks