Blog : Internet explorer -IE- is giving known runtime error while using innerHTML

May27


Problem:

I am using jquery(any ajax framework) to load content in a div. Then when user clicks on a link, this content should change.  Basically I was trying let user to add as many textboxes they want in a form.  I wrote a javascript method as follws and it work perfect in firefox or google chrome..


 

function adddiv(){
 
var rowtab1 = “<table>”;
rowtab1 = rowtab1 + “<tr>”;
rowtab1 = rowtab1 + “<td><input type=’text’ name=’short_descr["+ rowindex +"]‘ value=’Part-”+ rowindex+”‘ class=’tb-mandt-small’/></td>”;
rowtab1 = rowtab1 + “</tr>”;
rowtab1 = rowtab1 + “</table>”;
//append text box to the end of the div tag
document.getElementById(‘datarow’).innerHTML += rowtab1 ;
return;
}
 
This code doesnt not work in Internet explorer 6. It will give Uknown Run Time Error or Object of proprty doesnt support error
You can fix this code as given below, basically avoid using .innerHTML to get rid of this issue.
function adddiv(){
 
//creating html to add dynamically
var rowtab1 = “<table>”;
rowtab1 = rowtab1 + “<tr>”;
rowtab1 = rowtab1 + “<td><input type=’text’ name=’short_descr["+ rowindex +"]‘ value=’Part-”+ rowindex+”‘ class=’tb-mandt-small’/></td>”;
rowtab1 = rowtab1 + “</tr>”;
rowtab1 = rowtab1 + “</table>”;
//Get original div and add html content in it
originalDiv = document.getElementById(‘datarow’);
htmlText = originalDiv .innerHTML +  rowtab1;
newDiv = document.createElement(originalDiv .tagName);
newDiv.id = originalDiv .id;
newDiv.className = originalDiv .className;
newDiv.innerHTML = htmlText ;
oldDiv.parentNode.replaceChild(newDiv, originalDiv );
return;
}

Hope this helps…


Join Indian Community is USA
Posted in Software / Software category on May 27 2010, 04:57 PM
358 Views, 0 Comments, 1 Appreciations, Overall rating:
Tags: HTML, Java Script, Web Programming, JQuery
Post a comment | Appreciate this post | Report abuse |

Comments


 
X