Solved

# This is MOD?

Posted on 2005-05-10
3,487 Views
I assume Javascript doesn't have a Mod function.  I found this on the web:

function Mod(a, b) { return Math.floor(a/b)*b }

Here's my code:

for(y=0;y<oGrid.Rows.length;y++) {
var row = oGrid.Rows.getRow(y);
for(x=0;x<row.Band.Columns.length;x++) {
var cell = row.getCell(x);
if (Mod(y,2) == 0 ) {
cell.Element.style.backgroundColor = "#E0FFFF";
cell.Element.style.color = "blue";
} else {
cell.Element.style.backgroundColor = "#FFFFFF";
cell.Element.style.color = "blue";
}
}
}

This line:

if (Mod(y,2) == 0 ) {

This doesn't work they way I'd expect Mod to work.  What the above code is attempting to do is alternate row colors in a grid.  In runtime when I click on a row, the first two rows are one color and rows 3-6 are the other color.  ???  This, to my knowledge, is how Mod should work:

Mod(0,2) = 0
Mod(1,2) = 1
Mod(2,2) = 0
Mod(3,2) = 1
Mod(4,2) = 0
Mod(5,2) = 1

But according to the code above:

Mod(0,2) = 0
Mod(1,2) = 0
Mod(2,2) = 1
Mod(3,2) = 1
Mod(4,2) = 1

Huh?  How can 2/2 <> 0?

0
Question by:MIKEV

LVL 32

Accepted Solution

Yes Javascript has a mod function it's the percentage sign %

example

if (y%2 == 0 ) {

if (Mod(y,2) == 0 ) {
0

Author Comment

Cool, thanks!
0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

#### 754 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!