i want a user to go onto my website, and when they go onto my "stats" page, i want the table row with their name to highlight in green. I already have their name stored in a cookie.
I cant seem to get it working ... here is my code...
This gives all of the seperate rows an id ...
now, here is the function which all this is passed to ...
Please help me out here!
JavaScript Beginner at work
I cant seem to get it working ... here is my code...
This gives all of the seperate rows an id ...
Code:
draw_stats(nameArr[0], gamesplayedArr[0], winsArr[0], lossArr[0], winStreakArr[0], winPercentageArr[0], "Dave");
draw_stats(nameArr[1], gamesplayedArr[1], winsArr[1], lossArr[1], winStreakArr[1], winPercentageArr[1], "Dave (owner)");
draw_stats(nameArr[2], gamesplayedArr[2], winsArr[2], lossArr[2], winStreakArr[2], winPercentageArr[2], "Jonathan");
draw_stats(nameArr[3], gamesplayedArr[3], winsArr[3], lossArr[3], winStreakArr[3], winPercentageArr[3], "John");
draw_stats(nameArr[4], gamesplayedArr[4], winsArr[4], lossArr[4], winStreakArr[4], winPercentageArr[4], "Little John");
draw_stats(nameArr[5], gamesplayedArr[5], winsArr[5], lossArr[5], winStreakArr[5], winPercentageArr[5], "Kev");
draw_stats(nameArr[6], gamesplayedArr[6], winsArr[6], lossArr[6], winStreakArr[6], winPercentageArr[6], "Kev (barman)");
draw_stats(nameArr[7], gamesplayedArr[7], winsArr[7], lossArr[7], winStreakArr[7], winPercentageArr[7], "Paul");
draw_stats(nameArr[8], gamesplayedArr[8], winsArr[8], lossArr[8], winStreakArr[8], winPercentageArr[8], "Sean");
now, here is the function which all this is passed to ...
Code:
function draw_stats(name, games_played, wins, loss, win_streak, win_percentage, id_name) {
document.write("<tr align='center' id='" + id_name + "' bgcolor='white' onmouseover=\"this.bgColor='#eaffea'\" onmouseout=\"this.bgColor='white'\">");
document.write("<td class='font'>");
document.write(name);
document.write("</td>");
document.write("<td class='font'>");
document.write(games_played);
document.write("</td>");
document.write("<td class='font'>");
document.write(wins);
document.write("</td>");
document.write("<td class='font'>");
document.write(loss);
document.write("</td>");
document.write("<td class='font'>");
document.write(win_streak);
document.write("</td>");
document.write("<td class='font'>");
var value = Math.round(win_percentage * 100) / 100
document.write(value + "%");
document.write("</td>");
document.write("</tr>");
}
and then here is my loadCookie function, which is called when the page is loading ...
[code]
function loadCookie() {
cookie = document.cookie; // puts the value of the cookie into the variable "cookie"
allCookies = cookie.split(";"); // splits the cookie up into an array called "allCookieS"
if(allCookies.length > 0) { // if the array holds data, carry on!
for(x=0; x < allCookies.length; x++) { // look throught each slot in the "allCookies" array
if(foundIt == "yes") { // if the cookie is found, break the loop
break; // this statement breaks the loop
}
cookieValue = allCookies[x]; // stores each slots info in the variable "cookieValue" every time through the loop
for(y=0; y < profileNamesArr.length; y++) { // loops throught the selections array
if(foundIt == "yes") { // if the cookie is found, break the loop
break; // this statement breaks the loop
}
if(cookieValue == profileNamesArr[y]) { // if the cookie value is equal to a selection
[COLOR=red]if(window.location == "[URL unfurl="true"]http://www.freewebs.com/foxandhounds/team_stats.html")[/URL] {
document.getElementById(cookieValue).style.bgColor="green";
}[/color]
playerName = "Hello " + "<strong>" + cookieValue + "</strong>"; // change the onscreen name
var foundIt = "yes" // alert the loop that the cookie has been found
break; // break the loop by using this statement
}
}
}
if(foundIt != "yes") {
alert("Please choose your profile ...");
window.location = "[URL unfurl="true"]http://www.freewebs.com/foxandhounds/profile.html";[/URL]
}
}
else {
alert("cannot find any cookie data");
}
}
Please help me out here!
JavaScript Beginner at work