title: Cross browser compatibility on various javascript elements
body: <p>I am working on application to make it browser compatible. I have a jsp page which will call the Javascript functions for execution. Basically I am displaying a list of contents in my page for selection using a radio button. Here it goes:</p>
  
  <p>JSP Page :</p>
  
  <pre><code> &lt;script language="JavaScript"&gt;
          loadcodes(10,'codesTable','#TheCodes',' ' ,'desc','&lt;%=compositeDescTagName%&gt;','&lt;%=compositeDescFormName%&gt;','&lt;%=codeFormName%&gt;','&lt;%=codeIdFormName%&gt;','document.resourceform.&lt;%=Globals.ENFORCE_COMMENTS%&gt;');
      &lt;/script&gt;.
  </code></pre>
  
  <p>The above function will reference to the following js page: </p>
  
  <pre><code>function loadcodes(depth,tableId,dataSrc,onclickfunc,descFld,compositeDescTagName,compositeDescFormName,codeFormName,codeIdFormName,enforceCommentsFormName)
  {
      document.writeln("&lt;TABLE height=100% id=PrimaryTable dataSrc='" + dataSrc + "' cellSpacing=0 cellPadding=0 border=0&gt; &lt;TBODY&gt;");
      writeNode(depth,dataSrc,descFld,compositeDescTagName,compositeDescFormName,codeFormName,codeIdFormName,enforceCommentsFormName);
      document.writeln("&lt;/TBODY&gt;&lt;/TABLE&gt;");
  }
  
  function writeNode(depth,dataSrc,descFld,compositeDescTagName,compositeDescFormName,codeFormName,codeIdFormName,enforceCommentsFormName)
  {
      if (depth &lt;= 0)
          return;
      document.writeln("&lt;TR onclick=\"toggle(this,'" + dataSrc + "','" + compositeDescTagName + "','" + compositeDescFormName + "','" + codeFormName + "','" + codeIdFormName + "','" + enforceCommentsFormName + "')\" class=tree_indent&gt;");
          document.writeln("&lt;TD&gt;&lt;IMG dataFld='image' id=Icon class=tree_node&gt;");
      document.writeln("&lt;SPAN dataFld=" + descFld + " class=formtext&gt;&lt;/SPAN&gt;");
      document.writeln("&lt;SPAN dataFld=haschildren id=HasChildren style='DISPLAY:none'&gt;&lt;/SPAN&gt;&lt;SPAN dataFld=isleaf id=isleaf style='DISPLAY: none'&gt;&lt;/SPAN&gt;&lt;SPAN dataFld=composite_desc id=composite_desc style='DISPLAY:none'&gt;&lt;/SPAN&gt;");
      document.writeln("&lt;SPAN dataFld=composite_code id=composite_code style='DISPLAY:none'&gt;&lt;/SPAN&gt;");
      document.writeln("&lt;SPAN dataFld=composite_id id=composite_id style='DISPLAY:none'&gt;&lt;/SPAN&gt;");
      document.writeln("&lt;SPAN dataFld=comments_required id=comments_required style='DISPLAY:none'&gt;&lt;/SPAN&gt;");
      document.writeln("&lt;/TD&gt;&lt;/TR&gt;");
      document.writeln("&lt;TR style='DISPLAY: none' class=tree_indent&gt;");
          document.writeln("&lt;TD&gt;&lt;!-- next level --&gt;");
          document.writeln("&lt;TABLE class=tree_node id=node dataFld=node valign=top border=0 cellSpacing=1 cellPadding=1 &gt;");
          document.writeln("&lt;TBODY&gt;");
      writeNode(--depth,dataSrc,descFld,compositeDescTagName,compositeDescFormName,codeFormName,codeIdFormName,enforceCommentsFormName);
          document.writeln("&lt;/TBODY&gt;");
          document.writeln("&lt;/TABLE&gt;");
          document.writeln("&lt;/TD&gt;");
          document.writeln("&lt;/TR&gt;");
  }
  
  var selectedCode;
  function toggle(e,dataSrc,compositeDescTagName,compositeDescFormName,codeFormName,codeIdFormName,enforceCommentsFormName)
  {
    var nextRow;
    var nextRow1;
  
    nextRow = e.nextSibling;
  
    hc = e.all.HasChildren;
    var isleaf = e.all.isleaf;
  
      if (nextRow.style.display == "none" &amp;&amp; isleaf.innerText == "false")
      {
          nextRow.style.display = "";
          e.all.Icon.src = "/edcs/images/minus.gif";
  
          if (nextRow.all &amp;&amp; nextRow.all[2] &amp;&amp; !nextRow.all[2].dataSrc) 
          {
              nextRow.all[2].dataSrc = dataSrc;
          }
      } 
      else if (isleaf.innerText == "true")
      {
          // reset the bullet on the one already selected
          if (selectedCode &amp;&amp; selectedCode.all &amp;&amp; selectedCode.all.Icon)
              selectedCode.all.Icon.src = "/edcs/images/bullet.gif";
  
          e.all.Icon.src = "/edcs/images/right.gif";
  
          re=/'/g;
  
          var str = e.all.composite_desc.innerText.replace(re,"\\'");
  
          eval(compositeDescTagName + ".innerText = '"  + str + "'");
          eval(compositeDescFormName + ".value = '"  + str + "'");
          eval(codeFormName + ".value = '"  + e.all.composite_code.innerText + "'");
          eval(codeIdFormName + ".value = '"  + e.all.composite_id.innerText + "'");
          commentsEnforced = eval(enforceCommentsFormName + ".value");
          if (commentsEnforced == "false")
              eval(enforceCommentsFormName + ".value = '"  + e.all.comments_required.innerText + "'");
  
          selectedCode = e;
      }
      else
      {
          nextRow.style.display = "none";
          e.all.Icon.src = "/edcs/images/plus.gif";
      }
  }
  </code></pre>
  
  <p>This flow works well in IE browsers but not supported by other browsers. While searching I found the list of elements supported only by IE:</p>
  
  <ol>
  <li>DataSrc </li>
  <li>Datafld and also IMG datafld.</li>
  </ol>
  
  <p>Is there any alternative for the above elements with browsers or how could the modifications made in the code so that it is browser compatible? Kindly help and also it would be turn out be a template for cross browser testing. </p>