Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3884
  • Last Modified:

javascript/DHTML setAttribute onmouseover run function pass variable IE

Hi,
The following works perfectly in FF but not in IE,

<html>
<head>

<script>

function runstuff(tbodyID){
      var txt, l, td, tr, tbody
      tbody = document.getElementById(tbodyID)
  var frag = document.createDocumentFragment();

 
  for (var i = 1; i < 4; i++){
        tr = document.createElement("tr");
        for (var k = 1; k < 4; k++){
              var l = i + "-" + k
              td = document.createElement("td");
              td.setAttribute("onmouseover", "StartToolTip('" + l + "')");
              
              txt = document.createTextNode(l);
              td.appendChild(txt);
          tr.appendChild(td)
          }
    frag.appendChild(tr);
  }
tbody.appendChild(frag)
}

function StartToolTip(mytip){
      alert(mytip);
      
}
</script>
</head>


<body onload="runstuff('maindata')">
      <table>
            <thead><th>a</th><th>b</th><th>c</th></thead>
            <tbody id="maindata"></tbody>
      </table>
</body>
</html>

i've found plenty of questions about this, but cannot make any of the solutions work in both browsers.

Many thanks
Jon
0
jondanger
Asked:
jondanger
  • 2
1 Solution
 
TNameCommented:
Hi, try to replace this line

  td.setAttribute("onmouseover", "StartToolTip('" + l + "')");

with this one

  td.onmouseover= function() { StartToolTip(l); };
0
 
TNameCommented:
No, disregard my comment, it will not work correctly.
0
 
malfunction84Commented:
td.onmouseover = new Function("StartToolTip(\"" + l + "\");");
0
 
jondangerAuthor Commented:
Tname: i thought it had worked! the alert box appears in IE but the value was 3-3 for every cell. thanks for trying.

malfunction84: brilliant, i've been at this for hours :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now