View Full Version : updating element values in IE7

12-16-2008, 07:22 PM
I want to update the innerHTML of an element with data that I have gotten from an xml. First of all this all works in FF3 but not in IE7.

for the html element I have tried both:
<p id="fullday" class="news"></p> (preferred)
<div id="fullday" class="news"></div>

I want to update the text of fullday.
The Javascript I have tried:

document.getElementById("fullday").innerHTML = fullday; (where fullday is a string with the text I want)

also I have tried
var el = document.createElement('p');
el.innerHTML = fullday;
(where fullday is a div)

var el = document.createElement('p');
el.innerHTML = fullday;

All of these have worked beautifully in FF and not one has worked in IE

12-16-2008, 07:41 PM
Those all work in both browsers, the problem lies elsewhere (probably in how you pull and assign your xml). If you post the rest of your code, we might be able to help.

12-16-2008, 09:35 PM
I thought of that and tried updating with a simple "Hello World!" string and it still didn't work. In any case here's the code:

function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
var xmlDoc=xmlHttp.responseXML.documentElement;
var fullday = "Today's Master Torah Learning is available for dedication";
var amudyomi = "Today's Amud Yomi Learning is available for dedication";
var shasreview = "Today's Shas Review Learning is available for dedication";
var mishna = "Today's Mishna Learning is available for dedication";
var rambam = "Today's Rambam Learning is available for dedication";
var allShas = "";
var allMishna = "";
var none = xmlDoc.hasAttribute("none");
if(!none) {
for(j=1;j<xmlDoc.childNodes.length;j++) {
var dedication = xmlDoc.childNodes[j];
var donor = dedication.getElementsByTagName("donor")[0];
if(donor.getAttribute("display") == 1)
var dedicator = donor.firstChild.nodeValue+" Dedicated ";
var dedicator = "Dedication of ";

var receiver = dedication.getElementsByTagName("receiver")[0];
var dedicated = "";
for(i=0;i<receiver.childNodes.length;i++) {
var ded = receiver.childNodes[i];
var tn = ded.tagName;
var tv = ded.firstChild.nodeValue;
if(i>0 && i<receiver.childNodes.length) dedicated += ", and";
if(tn == "yartzeit") dedicated += " for the Yartzeit of "+tv;
if(tn == "shloshim") dedicated += " for the Shloshim of "+tv;
if(tn == "memory") dedicated += " in Memory of "+tv;
if(tn == "honor") dedicated += " in Honor of "+tv;
if(tn == "occasion") dedicated += " on the Occasion of "+tv;
if(tn == "other") dedicated += tv;
var learning = dedication.getElementsByTagName("learning")[0];
for(i=0;i<learning.childNodes.length;i++) {
var lrn = learning.childNodes[i];
var tn = lrn.tagName;
var tv = lrn.firstChild.nodeValue;
if(tn == "fullday" && tv == 1) fullday = dedicator+"Today's Master Torah Learning"+dedicated;
if(tn == "amudyomi" && tv == 1) amudyomi = dedicator+"Today's Amud Yomi Learning"+dedicated;
if(tn == "shasreview" && tv == 1) shasreview = dedicator+"Today's Shas Review Learning"+dedicated;
if(tn == "mishna" && tv == 1) mishna = dedicator+"Today's Mishna Learning"+dedicated;
if(tn == "rambam" && tv == 1) rambam = dedicator+"Today's Rambam Learning"+dedicated;
if(tn == "allShas" && tv == 1) allShas = dedicator+"All of Talmud Bavli"+dedicated;
if(tn == "allMishna" && tv == 1) allMishna = dedicator+"All of Mishna"+dedicated;

var el = document.createElement('p');
el.innerHTML = fullday;
var e = document.getElementById("amudyomi");
if(e != null)
e = document.getElementById("shasreview");
if(e != null)
e = document.getElementById("talmud");
if(e != null)
e.innerHTML=amudyomi+"<br />"+shasreview;
e = document.getElementById("mishna");
if(e != null)
e = document.getElementById("rambam");
if(e != null)

thanks for your help in advance.

12-16-2008, 09:49 PM
Nothing jumps out at me as being incompatible with IE, however since I don't have your XML to test, why don't you show me your "hello world" example code that doesn't work - I'll try to fix that.

As proof that your original post code works cross-browser, here's a simple innerHTML example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<script type="text/javascript">
// <![CDATA[

window.onload = function()
var my_id = "hey";
document.getElementById("my_id").innerHTML = my_id;

// ]]>

<div id="my_id"></div>


12-16-2008, 09:59 PM
Here's a example of my xml:

<?xml version='1.0' encoding='ISO-8859-1'?>
<dedications >
<date>19 Kislev 5769</date>
<donor display="1">The Proud Father</donor>
<honor>Our Baby Girl</honor>
<donor display="0">Dovid</donor>
<memory>the fallen of Mumbai</memory>
<occasion>Displaying the Dedications</occasion>

12-16-2008, 10:00 PM
btw, how do you get it to format when posting?

12-16-2008, 10:06 PM
Use [ code][ /code] and [ quote][ /quote].

why don't you show me your "hello world" example code that doesn't work - I'll try to fix that.

12-17-2008, 01:50 PM
you inspired me to do a comment out and find the offending line, which I did.

apparently IE does not like the node.hasAttribute() function. So I changed it to getAttribute() and now if works.

Thanks so much for your help.

12-17-2008, 07:08 PM
Anytime, though I don't feel like I helped all that much... lol