I have a code wich I´d like to alter to output a image instead of a number

The image should only be displayed for the so called pick output. There is a structure in the images I'd like to use, so if somebody could be so nice to have 1 or 2 explained, I can do the other 43 :)

Example, here is an working example of the code this far. http://www.coldcharlie.nl/lotto

What I want is that when a number pick is for example 6, this image will be shown alt text Please don't worry about the copyrights, I will make my own balls when the code design is finished.

Any help would be great.

<script type="text/javascript" src="http://jquery.com/src/jquery-latest.js"></script>

<div id="players"></div>
<div id="draws"></div>

<script type="text/javascript">

var players = {
Joop   : ["6","8","16","18","26","28","32","36","38","41"],
Marijke: ["7","10","14","18","24","29","30","34","39","40"],
Michel : ["4","5","11","16","21","27","33","36","42","44"],
Mario  : ["6","9","18","25","32","35","39","40","43","45"],
Diana  : ["2","6","8","17","22","23","33","36","42","45"],
Agnes  : ["3","5","10","15","26","29","32","37","41","44"],
Chris  : ["5","7","8","9","11","12","16","28","30","32"],
Jeannette: ["1","2","4","7","8","11","13","28","30","38"],
Wieger: ["1","2","3","7","10","13","14","22","23","27"],
Anita: ["6","13","15","17","21","26","32","33","43","45"],
Thea: ["1","3","5","7","10","17","19","20","22","38"],
Danny: ["3","7","11","15","22","28","32","37","40","43"],
Cindy: ["2","4","16","18","21","24","33","38","41","44"],
Hanneke: ["1","3","4","12","18","21","25","30","36","40"],
Willem: ["3","9","17","21","27","33","35","39","41","42"]
};

var draws = [ {

when: 'Datum: Zaterdag 08-08-2009',
picks:[2, 13, 15, 18, 21, 41]
},

{
when: 'Datum: Zaterdag 15-08-2009',
picks:[6, 19, 24, 25, 35, 37]
},

{
when: 'Datum: Zaterdag 22-08-2009',
picks:[8, 17, 23, 26, 37, 42]
}
];

var buildPlayers = function(){
var cont = $("#players");
for(player in players){
var html = ["<div>","<span class='name'>"+player+"</span>", "<ol class='picks'>"];
for(var i = 0; i < players[player].length; i++){
html.push("<li class='loss pick_"+players[player][i]+"'>"+players[player][i]+"</li>");
}

html.push("</ol>","</div>");
cont.append(html.join(""));
}
};

var buildDraws = function(){
var cont = $("#draws");
for(var i = 0; i < draws.length; i++){
var html = ["<div class='draw'>","<h4 class='drawNum'>Trekking "+(i+1)+"</h3>","<div class='date'>"+draws[i].when+"</div>","<ol class='picks'>"];
for(var j = 0; j < draws[i].picks.length; j++){
html.push("<li>"+draws[i].picks[j]+"</li>");
showWin(draws[i].picks[j]);
}
html.push("</ol>","</div>");
cont.append(html.join(""));
}
};

var showWin = function(winNum){
$(".pick_"+winNum).removeClass("loss").addClass("win");
};

$(function(){
buildPlayers();
buildDraws();
});
</script>
link|improve this question

I dont understand why the code doesn't show right, I'll try to change it. – Chris Aug 22 '09 at 18:27
feedback

1 Answer

up vote 0 down vote accepted

Change this

  for(var j = 0; j < draws[i].picks.length; j++) {
      html.push("<li>"+draws[i].picks[j]+"</li>");
      showWin(draws[i].picks[j]);
  }

to

  for(var j = 0; j < draws[i].picks.length; j++) {
      var img = '<img src="/images/ball-'
                     + draws[i].picks[j]
                     + '.jpg" alt="'
                     + draws[i].picks[j]
                     + '" />';
      html.push("<li>"+img+"</li>");
      showWin(draws[i].picks[j]);
  }

assuming that your images are named "ball-#" and located in the images directory.

link|improve this answer
I see this code tries to get an image, but when I look at the properties it doesn't show the image extension. I did upload a image called ball-6.jpg in the images folder – Chris Aug 22 '09 at 19:11
Sorry. I left the extension out of the construction of the url for the image. I've updated my answer. – tvanfosson Aug 22 '09 at 19:25
Great! works like a charm :) – Chris Aug 22 '09 at 19:55
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.