im just a beginner in javascript i just want to kown why is this happening?
[object HTMLImageElement] Introduction
[object HTMLImageElement] Schedule
[object HTMLImageElement] Speaker
im trying to put the image into an array with this code
var myEvent2 = new Array("Introduction","Schedule","Speaker");
bullet[0]= new Object();
bullet[0].picture="image2/bullet.jpg";
for(t=0;t<myEvent2.length;t++){
b[t]=new Image();
b[t].src=bullet[0].picture;
//document.body.appendChild(b[t]);
p[t]=document.createElement("p");
p[t].innerHTML =" "+myEvent2[t];
//document.body.appendChild(p[t]);
g[t]=b[t]+" "+myEvent2[t]+"<br>";
p2[t]=document.createElement("p");
p2[t].innerHTML =g[t];
document.body.appendChild(p2[t])
}
b[t] = new Image();
Creates a new image element.
g[t]=b[t]+" "+myEvent2[t]+"<br>";
You are now asking JScript to peform a string concatenation and include the
image element object as an item to concatenate. JScript calls the objects
.toString() method to retrieve a string representation of the object. In
most cases this would be the sort of string you are seeing [object
HTMLImageElement.
Try this:-
var myEvent2 =new Array("Introduction", "Schedule", "Speaker");
for (var i=0; i < myEvent2.length; i++)
{
var p = document.body.appendChild(document.createElement("p"));
var img = p.appendChild(document.createElement("img"));
img.src ="image2/bullet.jpg";
img.style.marginRight = "3ex";
p.appendChild(document.createTextNode(myEvent2[i]));
}
--
Anthony Jones - MVP ASP/ASP.NET