Dean, Thanks for the reply. I've been working with the jquery api just a bit today, and I really like it. Thanks for the reference!
PianoMan
Posts
-
Need Help Setting <img> src attribute -
Need Help Setting <img> src attributeI've hit a wall trying to use javascript to write a table with some image tags. I'm looping through an array of image names, then setting their src attribute. The function is creating the tags, but all that displays is the 'missing image' thumbnail. The function is fired via a button. Below is my code. Thanks!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex"><title>Testing Javascript</title>
<script type="text/javascript">
function getImages() {
// Declare variables
var allImages, vRow, vCell, vText, vImg;
var vCnt, i, j, x, y;
var vTable = document.createElement("TABLE");
var vTBody = document.createElement("TBODY");// Insert vBody into vTable
vTable.appendChild(vTBody);// create an array
var images = new Array();images[0] = "image1.jpg";
images[1] = "image2.jpg";
images[2] = "image3.jpg";// count values in the array
vCnt = images.length;// loop through the array of images and answers
for (i=0; i < vCnt; i++)
{
// create a row
vRow = document.createElement("TR");// create a TD tag vCell = document.createElement("TD"); // create IMG element var image = images\[i\]; vImg = document.createElement("IMG"); vImg.setAttribute("src", "images/" + image); // insert the img tag into the td tag vCell.appendChild(vImg); // insert the cell into the row vRow.appendChild(vCell); // insert the row into the table vTBody.appendChild(vRow);
}
// add the table to the doc
var vTableContainer = document.getElementById("vTableContainer");
vTableContainer.appendChild(vTable);
}
// end updatePage()
</script>
</head><body bgcolor = "#FFFFFF">
Javascript and Images
Trying to set the image source with js...
<form method="GET">
<input type="button" value="DISPLAY IMAGES" onClick="getImages();" />
</form></body>
</html> -
Images Won't display in IE 7Thanks for the reply. Well, I removed the javascript from the HTML page and put it in a js file, and now it works. Go figure... Thanks a lot, Microsoft. :(
-
Images Won't display in IE 7Thanks for the reply, however that did not fix this problem. The IE browser does display the little thumbnail box, which tells me the image tag is there, but this line of code vImg.src = images[i]; for some reason is not setting the source for the image. I've even tried hard coding in the source with no luck.
-
Images Won't display in IE 7Would someone please tell me why this js won't display images in IE 7, but works perfectly in Firefox? I'm using Windows XP, and I've double-checked all my settings in IE 7. Thanks!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Sample</TITLE><SCRIPT LANGUAGE="JavaScript">
window.onload = fnWrite;function fnWrite()
{
// Declare variables
var vTable = document.createElement("TABLE");
var vTBody = document.createElement("TBODY");
var vRow, vCell, vDiv, vImg;
var i;var images = new Array();
images[0] = "images/treble_f1.JPG";
images[1] = "images/treble_c1.JPG";
images[2] = "images/treble_d1.JPG";
images[3] = "images/treble_e1.JPG";// Insert vBody into vTable
vTable.appendChild(vTBody);// Insert a row
vRow = document.createElement("TR");
vTBody.appendChild(vRow);
vCell = document.createElement("TD");
vRow.appendChild(vCell);// Insert images
for (i=0; i<images.length; i++)
{
vDiv = document.createElement("DIV");
vCell.appendChild(vDiv);vImg = document.createElement("IMG"); vImg.src = images\[i\]; vImg.setAttribute("alt", "image"); vCell.appendChild(vImg);
}
// Insert the table
vTableContainer.appendChild(vTable);
}
</SCRIPT></HEAD>
<BODY>
<H1>Javascript Won't Work in IE 7</H1>
<div id="vTableContainer"></div></BODY>
</HTML>