Click here to Skip to main content

JavaScript

   

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
AnswerRe: attr disabled property is not working for FF Pinmemberjohny101519815:53 14 Feb '12  
GeneralRe: attr disabled property is not working for FF PinmemberramuAlla1:15 1 Mar '12  
AnswerRe: attr disabled property is not working for FF PinmemberEdward Nutting0:34 19 Feb '12  
QuestionHow can i use backbone.js PinmemberDeepthiTanguturi22:02 10 Feb '12  
AnswerRe: How can i use backbone.js PinmvpRichard MacCutchan23:50 10 Feb '12  
Questionpage loading [modified] PinmemberMember 790448220:22 8 Feb '12  
QuestionNeed Help Setting src attribute PinmemberPianoMan5:26 7 Feb '12  
I'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 <img> tags, but all that displays is the 'missing image' thumbnail. The function is fired via a button. Below is my code.
 
Thanks!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN" "http://www.w3.org/TR/html4/loose.dtd">
<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">
<h2>Javascript and Images</h2>
 
<div id="parentDiv">
 
<p>
Trying to set the image source with js...
</p>
 
<div id="childDiv">
 
<form method="GET">
<input type="button" value="DISPLAY IMAGES" onClick="getImages();" />
</form>
 
</div>
 
<div id="vTableContainer"></div>
 
</div>
</body>
</html>

AnswerRe: Need Help Setting src attribute PinmemberDean Oliver6:40 7 Feb '12  
GeneralRe: Need Help Setting src attribute PinmemberPianoMan16:24 7 Feb '12  
GeneralRe: Need Help Setting src attribute PinmemberDean Oliver21:56 7 Feb '12  
AnswerRe: Need Help Setting src attribute Pinmemberjohny1015198118:12 7 Feb '12  
AnswerRe: Need Help Setting src attribute Pinmembertwseitex2:50 19 Feb '12  
QuestionImages Won't display in IE 7 PinmemberPianoMan6:27 5 Feb '12  
AnswerRe: Images Won't display in IE 7 PinmvpRichard MacCutchan23:23 5 Feb '12  
GeneralRe: Images Won't display in IE 7 PinmemberPianoMan4:15 6 Feb '12  
GeneralRe: Images Won't display in IE 7 PinmvpRichard MacCutchan4:30 6 Feb '12  
GeneralRe: Images Won't display in IE 7 - SOLVED PinmemberPianoMan4:43 6 Feb '12  
GeneralRe: Images Won't display in IE 7 - SOLVED PinmvpRichard MacCutchan5:31 6 Feb '12  
AnswerRe: Images Won't display in IE 7 Pinmemberjsc423:41 14 Feb '12  
AnswerRe: Images Won't display in IE 7 Pinmembertwseitex2:59 19 Feb '12  
QuestionProblem with args.isValid in JS [modified] Pinmemberdayakar_dn22:14 1 Feb '12  
AnswerRe: Problem with args.isValid in JS Pinmemberjohny1015198122:36 1 Feb '12  
GeneralRe: Problem with args.isValid in JS Pinmemberdayakar_dn23:03 1 Feb '12  
GeneralRe: Problem with args.isValid in JS Pinmemberjohny1015198123:10 1 Feb '12  
Questionupdate several DIV using javascript with mysql data PinmemberSergio8410:09 30 Jan '12  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 21 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid