Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1463 How do I build a 10 times table in JavaScript where the numbers divisible by a dynamically changing X are highlighted?

irt.org | Knowledge Base | JavaScript | Table | Q1463 [ previous next ]

Q1463 How do I build a 10 times table in JavaScript where the numbers divisible by a dynamically changing X are highlighted?

Try:

<body bgcolor="#ffffff">

<style><!--
.cell { position: relative; }
//--></style>

<script language="JavaScript"><!--
var Cells = 100;

function highlight(cell) {
  var color;
  for (i=1;i<=Cells;i++) {
    color = "#ffffff";
    if (i%cell==0) color = "#ff0000";
    if (document.layers)
        window.document.layers['cell' + i].bgColor = color;
    else if (document.all)
        window.document.all['cell' + i].style.background = color;
  }
}

var Text = '<table><tr>';
for (i=1;i<=Cells;i++) {
  Text += '<td class="cell" id="cell' + i + '"><a href="javascript:;" onClick="highlight(' + i + ')">' + i + '</a></td>';
  if (i%10 == 0 && i<Cells) Text += '</tr>\n<tr>';

}
Text += '</tr></table>'
document.write(Text);
//--></script>

</body>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.