Web Analytics Made Easy -
StatCounter I do not have a clue. Tweaking required - CodingForum

Announcement

Collapse
No announcement yet.

I do not have a clue. Tweaking required

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I do not have a clue. Tweaking required

    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!!
    PHP Code:
        <td width="100%" align="center">
    <
    div id="dcontent" style="width:100%;height:25px"></div>
    <
    ilayer id="ns4dcontent" width=100height=25px><layer id="ns4dcontent2" width=100height=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
    An answer needs a question just as much as a question needs an answer. Deep eh!

  • #2
    Re: I do not have a clue. Tweaking required

    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);
    }



    }

    Comment


    • #3
      Thank you, I'd forgotten about this post, since then, with the help of adios, I've also managed to include styles as well.
      An answer needs a question just as much as a question needs an answer. Deep eh!

      Comment

      Working...
      X