Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2005, 08:06 AM   PM User | #1
sumanreddy
New to the CF scene

 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sumanreddy is an unknown quantity at this point
Dom Script code not working in Opeara browser..check given code

hai

the following code is working in Internet Explorer, but not working in Opera. Pls Check the code and give the solution, so that it should work in Opera Browser.

<html>
<head>
<script type="text/javascript">

var i=0;

function insRow()
{
var trow=document.getElementById('myTable').insertRow()

var tdata1=trow.insertCell(0)
var tdata2=trow.insertCell(1)
var tdata3=trow.insertCell(2)
var tdata4=trow.insertCell(3)
var tdata5=trow.insertCell(4)

tdata1.innerHTML="<input type='text' id='txt' >"
tdata2.innerHTML="<input type='CHECKBOX' id='chk'>"
tdata3.innerHTML="<textarea id='tarea'></textarea>"
tdata4.innerHTML="<select id='lov'></select>"
tdata5.innerHTML="<input type='button' id='btn' onclick=delrow(this)>"

document.forms[0].elements[i].id=document.forms[0].elements[i].id+i;
document.forms[0].elements[i+1].id=document.forms[0].elements[i+1].id+i;
document.forms[0].elements[i+2].id=document.forms[0].elements[i+2].id+i;
document.forms[0].elements[i+3].id=document.forms[0].elements[i+3].id+i;
document.forms[0].elements[i+4].id=document.forms[0].elements[i+4].id+i;


tname="txt"+i;
chkname="chk"+i;
tareaname="tarea"+i;
lovname="lov"+i;
btnname="btn"+i;

tid="txt"+i;
chkid="chk"+i;
tareaid="tarea"+i;
lovid="lov"+i;
btnid="btn"+i;


var txtid = document.getElementById(tid);
txtid.setAttribute("name",tname);

var chkid = document.getElementById(chkid);
chkid.setAttribute("name",chkname);

var tareaid = document.getElementById(tareaid);
tareaid.setAttribute("name",tareaname);

var lovid = document.getElementById(lovid);
lovid.setAttribute("name",lovname);


var btnid = document.getElementById(btnid);
btnid.setAttribute("name",btnname);
btnid.setAttribute("value","delete row");
i=i+5;
}
function delrow(curr_row)
{

document.getElementById('myTable').deleteRow(curr_row.parentNode.parentNode.rowIndex);
}

</script>
</head>

<body>
<form>

<table id="myTable" border="1">
</table>

<input type="button" onclick="insRow()" value="Insert row">

</form>

</body>
</html>
sumanreddy is offline   Reply With Quote
Old 02-04-2005, 08:56 PM   PM User | #2
hemebond
Senior Coder

 
Join Date: Jul 2004
Location: New Zealand
Posts: 1,315
Thanks: 0
Thanked 2 Times in 2 Posts
hemebond is an unknown quantity at this point
Please read the posting guidelines and wrap your code within code tags.
hemebond is offline   Reply With Quote
Old 02-04-2005, 09:26 PM   PM User | #3
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
http://www.htmlforums.com/showthread.php?threadid=53000
Willy Duitt is offline   Reply With Quote
Old 02-08-2005, 09:21 AM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
try using DOM level2 methods, instead of insertRow deleteRow


For instance, to insert a row with cells and inner content, you may start from using this piece of code (untested, but in theory should work). Develop it on your needs:

PHP Code:
var innerC = new Array()
innerC[0] = ['input','text','txt'];
innerC[1] = ['input','checkbox','chk'];
innerC[2] = ['textarea','','tarea'];
innerC[3] = ['select','','lov'];
innerC[4] = ['input','button','btn'];
var 
root document.getElementById('myTable');
var 
trow document.createElement('tr');

for(var 
i=0;i<innerC.length;i++){
var 
tdata document.createElement('td');
var 
elem document.createElement(innerC[i][0]);
if((
i!=2)||(i!=3){
elem.setAttribute('type',innerC[i][1]);
}
elem.setAttribute('id',innerC[i][2]);
if(
i==4){
elem.onclick=function(){delrow(this)}
}
tdate.appendChild(elem);
trow.appendChild(tdate);
}
root.appendChild(trow); 
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 02-08-2005 at 09:34 AM..
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:17 AM.


Advertisement
Log in to turn off these ads.