Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

Make inner.html, more compatible???

I have this code(partial):
----------------------------

function updateBar(change) {
   ofTotal += change;
   if(ofTotal <= 0){
         var pbarw = 0;
   }else{
            var pbarw = Math.round(barWidth * ofTotal);
            if (pbarw > barWidth){pbarw = barWidth;}
   }
   document.getElementById('percentNumeric').innerHTML = Math.round(pbarw *100/barWidth);//need to be more compatible
   getObj(progressBarId).style.width = pbarw;
}

function getObj(objid) {
   if (document.getElementById(objid)) {
      return(document.getElementById(objid));
   } else if (document.getElementsByName(objid)[0]) {
      return(document.getElementsByName(objid)[0]);
   } else if (document.all[objid]) {
      return(document.all[objid]);
   } else if (document.layers[objid]) {
      return(document.layers[objid]);
   } else {
      return false;
   }
}

//-->
</script>
</head>
<body onload="setBar();updateBar(0);">

<div id="totalBar" style="border:1px solid black;"><div id="progressBar"></div></div>

<div id="percentNumeric">The value is:</div>

</body>

---------------------------------
How do I make this line more browser compatible like the line below it???

document.getElementById('percentNumeric').innerHTML =...
Avatar of matt_mcswain
matt_mcswain

You can access it as a texNode instead, so something like:

   document.getElementById('percentNumeric').firstChild.nodeValue = Math.round(pbarw *100/barWidth);
Like this:

getObj('percentNumeric').innerHTML = Math.round(pbarw *100/barWidth);

Avatar of MJ

ASKER

Tried that but doesn't work because of  index reference in function
What index are you talking about?
ASKER CERTIFIED SOLUTION
Avatar of davidlars99
davidlars99
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...if (document.getElementsByName(objid)[0]) {.....  this part will always be ignored by -->  if(document.getElementById)