innerHTML problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • junal
    New Member
    • Jan 2007
    • 22

    innerHTML problem

    hi guys....can anybody tell me what is the problem with the following line?....it works in Firefox but doesn't work in IE !

    doc.getElementB yId("testbody") .innerHTML="";
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try
    Code:
    document.getElementById("testbody").innerHTML="";

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      the testbody is ID of what????

      Comment

      • junal
        New Member
        • Jan 2007
        • 22

        #4
        i forgot to mention that i declared var doc = document ; and ya testbody is an id . but still its not working :(

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Then post the rest of your code which contains the "testbody" element.

          Comment

          • iam_clint
            Recognized Expert Top Contributor
            • Jul 2006
            • 1207

            #6
            i need to see what element your trying to set innerHTML of.

            Comment

            • junal
              New Member
              • Jan 2007
              • 22

              #7
              Code:
               function createTable(id){ 
               
              	var hmrc=0;
              	var h=0;
              	var newrow;
              	var tbl;
              	var newcol , newinput;
               
              	var loopcounter=0;
               
              	tbl = doc.getElementById('testbody');
              	//create a new row
              	newrow = doc.createElement("TR");
              	newcol = doc.createElement("TD");
              	newcol.width = 200;
              	newinput = doc.createElement("input");
              	newinput.name = "head";
              	newcol.appendChild(newinput);
              	newrow.appendChild(newcol);
               
               
              		while ( loopcounter<x ){
               
              		newcol = doc.createElement("TD");
              		newcol.width = 200;
              		newinput = doc.createElement("input");
              		newinput.name = "newrow1table"+__uid1;
              		newinput.size = 20;
              		newinput.value = col1[loopcounter+1];
              		newcol.appendChild(newinput);
              		newrow.appendChild(newcol);
              		loopcounter++;
               
              		}
              	tbl.appendChild(newrow);
              	__uid1++;	
               
              	loopcounter=0;
              	newrow = doc.createElement("TR");
              	newcol = doc.createElement("TD");
              	newcol.width = 200;
              	newinput = doc.createElement("input");
              	newinput.name = "head";
              	newcol.appendChild(newinput);
              	newrow.appendChild(newcol);
               
              		while ( loopcounter<x ){
               
              		newcol = doc.createElement("TD");
              		newcol.width = 200;
              		newinput = doc.createElement("input");
              		newinput.name = "newrow2table"+__uid1;
              		newinput.size = 20;
              		newinput.value = col2[loopcounter+1];
              		newcol.appendChild(newinput);
              		newrow.appendChild(newcol);
              		loopcounter++;
               
              		}
              	tbl.appendChild(newrow);
              	__uid1++;	
               
              	h=parseInt (doc.newtable.hmr.value);
              	//alert(h);
               
              	hmrc++;
               
              		while (hmrc<=h){
               
              			loopcounter=0;
               
              			newrow = doc.createElement("TR");
              			newcol = doc.createElement("TD");
              			newcol.width = 200;
              			newinput = doc.createElement("input");
              			newinput.name = "head"+hmrc;
              			newinput.value= "test"+hmrc;
              			newcol.appendChild(newinput);
              			newrow.appendChild(newcol);
               
              				while ( loopcounter<x ){
               
              				newcol = doc.createElement("TD");
              				newcol.width = 200;
              				newinput = doc.createElement("input");
              				newinput.name = "env"+loopcounter;
              				newinput.size = 20;
              				newinput.value = "";
              				newcol.appendChild(newinput);
              				newrow.appendChild(newcol);
              				loopcounter++;
               
              			}	
               
              			tbl.appendChild(newrow);
              			hmrc++;
              		}
               
               
              	}
              </script>
               
               
               
              <form >
              <body>
              <tbody ID="testbody">
              </tbody>
              </body>
              <input type=button onclick = function ())
              </form>

              i have just given some sample here !...this is not exact code where im working now.....it works in Firefox that means nothing wrong with the code right !. my question is why it doesn't work in IE ! it says unknown run time error.thx everybody .

              Comment

              • junal
                New Member
                • Jan 2007
                • 22

                #8
                one thing i have to say that this onclick button creates rows right. thing is i have a refresh button so it clears the rows and reform the table with the new input. so what im trying to do here is first im making previous tables data null and replacing with new values.

                Comment

                • mgast
                  New Member
                  • Sep 2006
                  • 9

                  #9
                  First of all, you will find this link useful for making sure your pages work correctly in IE.

                  If you are trying to empty a table, the best option would be to run a dom function that removes all the child nodes.

                  Comment

                  • AricC
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1885

                    #10
                    Originally posted by junal
                    function createTable(id) {

                    var hmrc=0;
                    var h=0;
                    var newrow;
                    var tbl;
                    var newcol , newinput;

                    var loopcounter=0;

                    tbl = doc.getElementB yId('testbody') ;
                    //create a new row
                    newrow = doc.createEleme nt("TR");
                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "head";
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);


                    while ( loopcounter<x ){

                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "newrow1table"+ __uid1;
                    newinput.size = 20;
                    newinput.value = col1[loopcounter+1];
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);
                    loopcounter++;

                    }
                    tbl.appendChild (newrow);
                    __uid1++;

                    loopcounter=0;
                    newrow = doc.createEleme nt("TR");
                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "head";
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);

                    while ( loopcounter<x ){

                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "newrow2table"+ __uid1;
                    newinput.size = 20;
                    newinput.value = col2[loopcounter+1];
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);
                    loopcounter++;

                    }
                    tbl.appendChild (newrow);
                    __uid1++;

                    h=parseInt (doc.newtable.h mr.value);
                    //alert(h);

                    hmrc++;

                    while (hmrc<=h){

                    loopcounter=0;

                    newrow = doc.createEleme nt("TR");
                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "head"+hmrc ;
                    newinput.value= "test"+hmrc ;
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);

                    while ( loopcounter<x ){

                    newcol = doc.createEleme nt("TD");
                    newcol.width = 200;
                    newinput = doc.createEleme nt("input");
                    newinput.name = "env"+loopcount er;
                    newinput.size = 20;
                    newinput.value = "";
                    newcol.appendCh ild(newinput);
                    newrow.appendCh ild(newcol);
                    loopcounter++;

                    }

                    tbl.appendChild (newrow);
                    hmrc++;
                    }


                    }
                    </script>



                    <form >
                    <body>
                    <tbody ID="testbody">
                    </tbody>
                    </body>
                    <input type=button onclick = function ())
                    </form>



                    i have just given some sample here !...this is not exact code where im working now.....it works in Firefox that means nothing wrong with the code right !. my question is why it doesn't work in IE ! it says unknown run time error.thx everybody .
                    In your onclick you are calling function you should call the name of the function here. Also, you have some spacing issues and you should use quotes around the element attributes. Ex.
                    Code:
                    <input type="button" onclick="YourJavascriptFunction()" />
                    In addition you need to close every tag you open ie. <tag>Stuff</tag> or use the method in my example above for your input tag.

                    Comment

                    Working...