I'm first going to nitpick at your code.
Hopefully this will leave less to be picked at in all your new code. (boogyman: I'm glad I read your message before posting, because I hadn't thought to remove the <font>.)
Do you know how to read errors in your browser? If you're using IE, click the yellow warning-sign at bottom-left. If Firefox, Tools > Error Console.
From Firefox:
Code:
"%EventTypeName%" is not a function
http://localhost/lib/JS/test4.html
Line 8
The parentheses after your string tell the browser to call the string as a function. Removing those, "Error event" displays in red at the screen's top. Wait, I know the string didn't start out that way...
Code:
if (str="Error event")
This assigns "Error event" to str and then takes that string's truth value (only false for empty strings). You want this (I added spaces because I like them):
Code:
if (str == "Error event")
Finally, the whole string is to be colored so we don't need to call str.replace:
Code:
document.write('<span style="color: #FF0000">Error event</span>');
For that matter, we could use a switch..case statement for much more readable code:
Code:
var str='%EventTypeName%';
var hex;
switch(str){
case 'Error event':
hex = '#FF0000';
break;
case 'Warning event':
hex = '#FFFF00';
break;
case 'Information event':
hex = '#000000';
}
document.write('<span style="color: ' + hex + '">' + str + '</span>');
Of course, we can put it in a function as you did earlier, but I'll also strip the <span> tag because we can use the existing <td>s:
Code:
function getColor(str){//Color font if it matches certain parameters
switch(str){
case 'Error event':
return '#FF0000';
case 'Warning event':
return '#FFFF00';
case 'Information event':
return '#000000';
}
}
OK, I'm done with that. Here are my thoughts for the rest of the code... (And I do expect you to try coding this.)
Add an id attribute to the table; I don't care what it is, so I'll call it 'foo'. var foo = document.getElementById('foo'); and then you can loop through the table's 'rows' property, which is an array-like object of <tr> elements, and get the first cell:
Code:
for(var i = 0; i < foo.rows.length; i++){
var type = foo.rows[i].cells[0];
//...
}
Now we just have to assign to the cell's 'style.color' property according to its innerHTML.
Bookmarks