PDA

View Full Version : insertRow not working in Mozilla but works in IE


ravikrishnasai
08-23-2007, 04:39 PM
Hi, my issue is the below code is not working in Mozilla browser. I want to generate a file item whenever i click a link. the corresponding script method is called when i click the link and also the table body which it refers. In IE the new file items are generating fine but in Mozilla one small horizontal space is generated each time instead of file item. appreciate you help.

function addFile()
{
if(document.all){
alert("IE");
var table = document.all["fileInput"]
var row = table.insertRow();
row.value = upload_number;
var cell = row.insertCell(0);
cell.innerHTML= "<tr valign=top><td colspan=2 class=txt-label><crTag:displayText Text="" keyText=""/></td><td width=429>";
cell = row.insertCell(0);
cell.innerHTML= "<div align=left>";
cell = row.insertCell(0);
cell.innerHTML = "<input class=input type=file name='filename"+upload_number+"' id=fileName />";
cell = row.insertCell(0);
cell.innerHTML = "</div></td></tr>";
cell = row.insertCell(0);
upload_number++;
}
else{
alert("mozilla");
var table = document.getElementById("fileInput");
var row = table.insertRow(0);
row.value = upload_number;
var cell = row.insertCell(0);
cell.innerText= "<tr valign=top><td colspan=2 class=txt-label><crTag:displayText Text="" keyText=""/></td><td width=429>";
cell = row.insertCell(1);
cell.innerText= "<div align=left>";
cell = row.insertCell(2);
cell.innerText = "<input class=input type=file name='filename"+upload_number+"' id=fileName />";
cell = row.insertCell(3);
cell.innerText = "</div></td></tr>";
cell = row.insertCell(4);
upload_number++;
}
}

Below the table that the method refers:-

<table id="fileInput" border="0" cellspacing=1 cellpadding=1 width="100%" >
<div align="left">
<input class="input" type="file" name="filename" id="fileName" />
<div><a href="javascript:addFile();"><crTag:displayText Text="Attach More Files" keyText="" locale="<%=locale%>"/></a></div>
<!-- style="display:none;" -->
</div>
</table>

mcjwb
08-23-2007, 06:39 PM
You've got quotes conflicting with quotes in this line:
cell.innerText= "<tr valign=top><td colspan=2 class=txt-label><crTag:displayText Text="" keyText=""/></td><td width=429>";
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
<!--
var upload_number=0;
function addFile()
{
var table
if(document.all){
table = document.all["fileInput"];
}
else if(document.getElementById){
table = document.getElementById("fileInput");
}
var row = table.insertRow(upload_number+1);
row.value = upload_number;
var cell1 = row.insertCell(0);
cell1.innerHTML= "<tr valign='top'><td colspan='2' class='txt-label'><crTag:displayText Text='' keyText=''/></td><td width='429'>";
var cell2 = row.insertCell(1);
cell2.innerHTML= "<div align='left'>";
cell2.innerHTML += "<input class='input' type='file' name='filename"+upload_number+"' id='fileName"+upload_number+"' />";
cell2.innerHTML += "</div></td></tr>";
upload_number++;
}
//-->
</script>
</head>
<body>
<table id="fileInput" border="0" cellspacing="1" cellpadding="1" width="100%" >
<tr><td></td><td colspan="2" width="429">
<div align="left">
<input class="input" type="file" name="filename" id="fileName" />
</div>
</td>
</tr>
</table>
<div align="left">
<div><a href="javascript:addFile();"><crTag:displayText Text="Attach More Files" keyText="" locale="<%=locale%>"/>add</a></div>
</div>
</body>
</html>