Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Please read the posting guidelines and wrap your code within code tags.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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); 
    Last edited by Kor; 02-08-2005 at 10:34 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •