0

My array looks like this:

var imagetitle = new Array()
imagetitle[0] = "One two tree";
imagetitle[1] = "Zero One seven abc";
imagetitle[2] = "qwe qwe qwe";
imagetitle[3] = "rerere erere weqwe";

Imagetitle is used as title in HTML later. Problem is that when I use it like this, It display only 1st word of string, not full string.

function showimage() {
var div_sa_slikom = document.createElement("div");
div_sa_slikom.innerHTML = "<a href="+imagetarget[i_image]+" title="+imagetitle[i_image]+" target='_parent'><img style='border:none;' src="+imageurl[i_image]+" border='0' title="+imagetitle[i_image]+" alt="+imagetitle[i_image]+" /></a>";
var container = document.getElementById("slike_rotator");
container.appendChild(div_sa_slikom);
}
5
  • 2
    How are you setting the title? Commented Oct 28, 2012 at 14:33
  • 1
    You'll have to show us the part where you use it - there's nothing wrong with what you've posted. Commented Oct 28, 2012 at 14:33
  • You're missing a semi colon in the above - doubt that's related though; probably just a typo in the question. var imagetitle = new Array(); Commented Oct 28, 2012 at 14:34
  • 1
    Show the code where you call imagetitle Commented Oct 28, 2012 at 14:36
  • You didn't initialize i_image ! Commented Oct 28, 2012 at 14:41

1 Answer 1

5

Your problem is that the HTML you're building is missing quotes.

You're building

title=One two tree

instead of

title="One two tree"

Replace your function with

function showimage() {
   var div_sa_slikom = document.createElement("div");
   div_sa_slikom.innerHTML = '<a href="'+imagetarget[i_image]+'" title="'+imagetitle[i_image]+'" target="_parent">'
       + '<img style="border:none;" src="'+imageurl[i_image]+'" border=0 title="'+imagetitle[i_image]+'" alt="'+imagetitle[i_image]+'">'
       + '</a>';
   var container = document.getElementById("slike_rotator");
   container.appendChild(div_sa_slikom);
}
1
  • You probably didn't fix all quotes. I edited my answer with the complete function. Commented Oct 28, 2012 at 15:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.