Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript to change an image source

Posted on 2011-03-17
2
Medium Priority
?
174 Views
Last Modified: 2012-05-11
I want to use javascript to change the src for images in a pretty lengthy web-based report.  Code below is stripped down to the very basics, but doesn't work.  It correctly alerts with the Pic.id, and it changes the desired border, so I know it's close.  Any ideas for getting it to load the new src?

I'm on a windows7 platform for testing (not a server).  I don't think this is the problem thought, because the ATL and BEL images load correctly in the basic html.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
	function Ready() {
		alert("step1");
		var Pic = document.getElementById("r1c1");
		Pic.src="gif\HOU.Capacity.0307_0313.gif";
		Pic.border="4";
		Pic.width="100%";
		alert(Pic.id);
	}
</script>
</head>
<body onLoad="Ready()">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
	<tr>
		<td width="50%"><img id="r1c1" border="0" src="gif\ATL.Capacity.0307_0313.gif" width="100%"></td></td>
		<td width="50%"><img id="r1c2" border="0" src="gif\BEL.Capacity.0307_0313.gif" width="100%"></td></td>
	</tr>
</table>
</body>
</html>

Open in new window

0
Comment
Question by:motokent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 35162123
Don't set the width a second time (line 11) :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
	function Ready() {
		//alert("step1");
		var Pic = document.getElementById("r1c1");
		Pic.src="http://www.symbian-freak.com/images/news/07/11/android01.jpg";
		Pic.border="4";
		//Pic.width="100%";
		//alert(Pic.id);
	}
</script>
</head>
<body onLoad="Ready()">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
	<tr>
		<td width="50%"><img id="r1c1" border="0" src="http://www.droid-life.com/wp-content/uploads/2010/09/angry-birds-game.png" width="100%"></td></td>
		<td width="50%"><img id="r1c2" border="0" src="http://www.bazaarvoice.com/blog/wp-content/uploads/begging.jpg" width="100%"></td></td>
	</tr>
</table>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:motokent
ID: 35162237
Thank you.  It worked great.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read on to get a few ideas on how to promote your next corporate event.
Check out what's been happening in the Experts Exchange community.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question