PDA

View Full Version : I do not have a clue. Tweaking required


Jeepers
06-27-2002, 11:03 PM
I got this code from somewhere, but I have no idea where. I will be using it to write the results of a javascript calculation that has three lines and using a table to position them. The only way I can get it to write the three lines is by duplicating the code three times within the target cells but with diffrent id's and function names. Is there a more elegant / code efficient way of doing it. BTW I have no idea how this works!!
<td width="100%" align="center">
<div id="dcontent" style="width:100%;height:25px"></div>
<ilayer id="ns4dcontent" width=100% height=25px><layer id="ns4dcontent2" width=100% height=25px></layer></ilayer>
<script>
function altercontent(myStr){
//if IE 4+
if (document.all)
dcontent.innerHTML=myStr;
//else if NS 4
else if (document.layers){
document.ns4dcontent.document.ns4dcontent2.document.write(myStr);
document.ns4dcontent.document.ns4dcontent2.document.close();
}
//else if NS 6 (supports new DOM)
else if (document.getElementById){
rng = document.createRange();
el = document.getElementById("dcontent");
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(myStr);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}}
</script>
</td>

tamienne
07-01-2002, 08:13 PM
Just have this is the table cells...


<div id="dcontentcell1" style="width:100%;height:25px"></div>
<ilayer id="ns4dcontentcell1" width=100% height=25px><layer id="ns4dcontentcell1_2" width=100% height=25px></layer></ilayer>


have this just once...
function altercontent(myStr,divname,layername){

if (document.all) {
document.all(divname).innerHTML=myStr;
} else if (document.layers){
lname=layername+"_2";
document.layers[layername].document.layers[lname].document.write(myStr);
document.layers[layername].document.layers[lname].document.close();
} else if (document.getElementById){
rng = document.createRange();
el = document.getElementById(divname);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(myStr);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}



}

Jeepers
07-01-2002, 08:30 PM
Thank you, I'd forgotten about this post, since then, with the help of adios, I've also managed to include styles as well.