Current location: Hot Scripts Forums » General Web Coding » JavaScript » Image Rotation Help


Image Rotation Help

Reply
  #1 (permalink)  
Old 12-04-06, 08:25 AM
aliciany aliciany is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Image Rotation Help Needed

I have the following script and need the image to appear in a specific place on a page. Can any one give me some direction?

Thanks!
aliciany

***************************************
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>
<SCRIPT language=JavaScript>

var img_width = "468";
var img_height = "60";
var img_title = "Click Here";


var ad=new Array()
ad[0]='trendy_baby_ad.gif';
ad[1]='ad_2.gif';
ad[2]='ad_3.gif';


var links=new Array()
links[0]='http://www.thetrendybebe.com';
links[1]='http://www.citizensbank.com';
links[2]='http://www.ethos.com';

var xy=Math.floor(Math.random()*ad.length);
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</SCRIPT>


<body>



</body>
</html>

Last edited by Nico; 12-06-06 at 12:10 PM. Reason: Please use [code] wrappers when posting code.
Reply With Quote
  #2 (permalink)  
Old 12-04-06, 11:32 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
please use [ code] wrappers

what specific place? you could do it like this:
Code:
document.getElementById("container").htmlText = '<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>';

<div id="container"></div>
or you could simply change the source of the image:
Code:
document.getElementById("image").src= ad[xy];
document.getElementById("image").width = img_width;
document.getElementById("image").height = img_height;

<img src="" id="image" width="" height="">
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 12-04-06, 06:38 PM
aliciany aliciany is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Rotating Image Help Needed Again

I am having a problem with this script.

I enclosed the entire coded page of the page I am having a problem on. The Image and Link rotation are working, but I can't get the image to appear in the correct place on the page (I noted on the page with the copy IMAGE AND LINK HERE where it should be).

Any help is appreciated.

Thanks in advance.

aliciany
__________________________________________________ _
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta name="GENERATOR" content="PageBreeze Free HTML Editor (http://www.pagebreeze.com)">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" >
<title>Ridgewood Newcomers</title>

<style>
<!--
h1 { font-family: Arial, sans-serif; font-size: 30px; }
h2 { font-family: Arial, sans-serif; font-size: 18px; }

body,p,b,i,em,dt,dd,dl,sl,caption,th,td,tr,u,blink,select,option,form,div,li { font-family: Arial, sans-serif; font-size: 12px; }
-->
</style>
	<script language="JavaScript">

  btn1_on = new Image();   btn1_on.src = "images/nav_home.gif";
  btn1_off = new Image();  btn1_off.src = "images/nav_home_onclick.gif";

  btn2_on = new Image();   btn2_on.src = "images/nav_about_us.gif";
  btn2_off = new Image();  btn2_off.src = "images/nav_about_us_onclick.gif";

  btn3_on = new Image();   btn3_on.src = "images/nav_calendar.gif";
  btn3_off = new Image();  btn3_off.src = "images/nav_calendar_onclick.gif";

  btn4_on = new Image();   btn4_on.src = "images/nav_special_interest.gif";
  btn4_off = new Image();  btn4_off.src = "images/nav_special_interest_onclick.gif";

  btn5_on = new Image();   btn5_on.src = "images/nav_resources.gif";
  btn5_off = new Image();  btn5_off.src = "images/nav_resources_onclick.gif";

  btn6_on = new Image();   btn6_on.src = "images/nav_join_us.gif";
  btn6_off = new Image();  btn6_off.src = "images/nav_join_us_onclick.gif";

function imageOn(name){
  document.images[name].src = eval(name + '_off.src');
}

function imageOff(name){
  document.images[name].src = eval(name + '_on.src');
}
		</script>
<SCRIPT language=JavaScript>

var img_width = "468";
var img_height = "60";
var img_title = "Click Here";


var ad=new Array()
ad[0]='trendy_baby_ad.gif';
ad[1]='ad_2.gif';
ad[2]='ad_3.gif';


var links=new Array()
links[0]='http://www.thetrendybebe.com';
links[1]='http://www.citizensbank.com';
links[2]='http://www.ethos.com';

var xy=Math.floor(Math.random()*ad.length);
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</SCRIPT>
		
		
</head>
<div align="center"><body bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<a name="top"></a>
<table width="778" border="0" cellspacing="0" cellpadding="0" bgcolor="#260751">
<tr>
<td><img src="images/top_banner_left.gif" alt="" width="208" height="76" border="0"></td>
<td><font color="#FFFFFF">IMAGE AND LINK HERE</font></td>
<td><img src="images/top_banner_right.gif" alt="" width="101" height="75" border="0"></td>
</tr>
<tr>
<td colspan="3" valign="top"><img src="images/top_banner_middle.gif" alt="" width="777" height="14" border="0"></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0">
<tr>
<td><a href="index.html" onMouseOver="imageOn('btn1')" onMouseOut="imageOff('btn1')"><img src="images/nav_home.gif" alt="" width="129" height="27" border="0" name="btn1"></a></td>
<td><img src="images/nav_about_us_onclick.gif" alt="" width="124" height="27" border="0" name="btn2"></td>
<td><a href="calendar.html" onMouseOver="imageOn('btn3')" onMouseOut="imageOff('btn3')"><img src="images/nav_calendar.gif" alt="" width="127" height="27" border="0" name="btn3"></a></td>
<td><a href="special_interest.html" onMouseOver="imageOn('btn4')" onMouseOut="imageOff('btn4')"><img src="images/nav_special_interest.gif" alt="" width="125" height="27" border="0" name="btn4"></a></td>
<td><a href="resources.html" onMouseOver="imageOn('btn5')" onMouseOut="imageOff('btn5')"><img src="images/nav_resources.gif" alt="" width="127" height="27" border="0" name="btn5"></a></td>
<td><a href="join_us.html" onMouseOver="imageOn('btn6')" onMouseOut="imageOff('btn6')"><img src="images/nav_join_us.gif" alt="" width="146" height="27" border="0" name="btn6"></a></td>
</tr>
</table>
<br>
<table width="777" border="0">
<tr>
<td width="150" valign="top">
<font size="2" color="#000000"><BR>
<a href="#board">2006-07 Board</a><br><BR>
<a href="#fundraising">Fundraising Efforts</a><BR><BR>
<a href="#friends">First Friends</a><BR><BR>
<a href="#childcare">Childcare During Luncheons</a><BR><BR>
<a href="#referral">Newcomer Referral<BR>Service</a><BR><BR>
<a href="#neat">Newcomers Emergency<BR>Assistance Team (NEAT)</a><BR><BR>
</font>
</td>
<td><table border="0" cellpadding="20"><tr><td valign="top">
<h2>About Us</h2>
The Ridgewood Newcomers Club is a program of the YWCA of Bergen County. For over 50 years, our club has been bringing new residents in the community together for friendship and fun. With a membership of more than 300 families, Newcomers is a great way to meet people and get involved in the community. Newcomers is run exclusively by volunteers who have recently moved to the area. Each year, Newcomers hosts a wide variety of activities and events aimed at the diverse interests of our membership. In addition to monthly luncheons, Newcomers also supports over 15 interest groups which include wine & cheese parties, book groups, playgroups, and gourmet club. Plus, there are groups organized for husbands and Ex-Pats/Re-Pats. Just recently we added a new interest group called "Little Newcomers," which organizes local outings for parents and children to enjoy together. There is truly something for everyone! Newcomers hosts a new member reception every summer, but residents in the Ridgewood area can join Newcomers at anytime during the year. There really isn't an easier way to make new friends, get to know a wonderful community and have lots of fun in the process! Please give us a call!
<BR><BR><a href="#top">Back to top</a><br><BR>
<a name="board"></a>
<h2>2006-2007 Board</h2>
<table width="550" border="0">
<tr valign="top">
<td>President</td><td>Winnie Atterbury O'Keefe<BR><BR></td></tr>
<tr valign="top"><td>1st Vice President</td><td>Alicia Simone<BR><BR></td></tr>
<tr valign="top"><td>Treasurer</td><td>Ann Addiego<BR><BR></td></tr>
<tr valign="top"><td>Secretary</td><td>Vanessa Druckman<BR><BR></td></tr>
<tr valign="top"><td>Past President</td><td>Cheryl Post<BR><BR></td></tr>

<tr valign="top"><td>Afternoon Socials - 2nd Vice President</td><td>Anita Srivastava</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Caroline Taylor</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Laura Cohan<BR><BR></td></tr>

<tr valign="top"><td>Evening Socials - 3rd Vice President</td><td>Jill Sullivan</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Eileen Seaman</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Liz Aktar<BR><BR></td></tr>

<tr valign="top"><td>Family Fun - 4th Vice President</td><td>Michelle Anderson</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Nicole Liu</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Maggie McCormick<BR><BR></td></tr>
<tr valign="top"><td>Membership</td><td>Joy Scott<BR><BR></td></tr>
<tr valign="top"><td>Publicity</td><td>Paige McElroy<BR><BR></td></tr>
<tr valign="top"><td>Interest Groups</td><td>Cynthia Rae<BR><BR></td></tr>
<tr valign="top"><td>Hospitality</td><td>Mary Dougherty</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Cecily Healy<BR><BR></td></tr>
<tr valign="top"><td>Ways & Means</td><td>Laurie Carr</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Silvana Penava<BR><BR></td></tr>
<tr valign="top"><td>Newsletter</td><td>Deanne Dunne</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Lucy Probert<BR><BR></td></tr>
<tr valign="top"><td>Communications</td><td>Carol Cho<BR><BR></td></tr>
<tr valign="top"><td>Member Services</td><td>Kumiko Suzuki<BR><BR></td></tr>
<tr valign="top"><td>YWCA Advisor</td><td>Joan Groome<BR><BR></td></tr>
<tr valign="top"><td>Nominating</td><td>Christine McCandless</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Victoria Schnure<BR><BR></td></tr>
<tr valign="top"><td>Fundraising</td><td>Isabelle Leluc</td></tr>
<tr valign="top"><td>&nbsp;</td><td>Christina Gibbons<BR><BR></td></tr>
</table>
<a href="#top">Back to top</a><br><BR>
<a name="fundraising"></a>
<h2>Fundraising Efforts</h2>
As an integral part of the YWCA and the Ridgewood community, the Newcomers Club of Ridgewood raises thousands of dollars each year for the the YWCA.  Throughout the year, the Newcomers' Club hosts several fundraising events, big and small, for which the proceeds go to the YWCA's Encore Plus program and YWCA Rape Crisis Center.  Most recently, fundraising events have included, Casino Night, Newcomers' Cookbook, Superbowl Squares, Fashion Shows, Art Show and Auction.  The Newcomers' Club also supports the YWCA's annual Travels and Treasure Auction with donations; past donations have been crafts, home made dinners and fine wines.  
<BR><BR><a href="#top">Back to top</a><br><BR>
<a name="friends"></a>
<h2>First Friends</h2>
First Friends is a service provided to connect first-year Newcomers with an "experienced" Newcomer with common experiences (e.g., living in the same neighborhood, moved from the same town, having children the same ages, etc.).   A First Friend can help introduce you to the area, answer questions about the Newcomers organization, suggest places to go and things to do. To sign up, contact Mary Dougherty or Cecily Healy.
<BR><BR><a href="#top">Back to top</a><br><BR>
<a name="childcare"></a>
<h2>Child Care During Afternoon Luncheon Programs</h2>
Child Care is available at the YWCA (112 Oak St., Ridgewood) for all afternoon Newcomers luncheon programs at the YWCA. Reservations must be made no later than the Friday prior to each program and are on a first-come, first-served basis. You must pay for reservations unless you cancel by noon on the Tuesday prior to the program.  Child Care begins at 12:30 p.m. (Note: Children will not be accepted after 1:00 p.m.) Costs are as follows:<BR>
<ul type="circle">
<li>$5.00 for Infant Care (2 months to 2-1/2 years)</li>
<li>$3.50 for the first child in Playtime (2-1/2 to 6 years)</li>
<li>$2.00 for each additional child in Playtime</li>
</ul>
<BR><BR><a href="#top">Back to top</a><br><BR>
<a name="referral"></a>
<h2>Newcomer Referral Service</h2>
Newcomers maintains a list of doctors, plumbers, contractors, and other professionals who have been recommended by our members.  Contact Kumiko Suzuki for more information.
<BR><BR><a href="#top">Back to top</a><br><BR>
<a name="neat"></a>
<h2>Newcomer Emergency Assistance Team (NEAT)</h2>
If you or any Newcomer you know needs assistance due to a medical or family crisis, we can provide meals, childcare and/or transportation.  Contact Kumiko Suzuki for more information.
<BR><BR><a href="#top">Back to top</a><br><BR>

</td>
</td></tr></table>
</tr>
</table>


</body>
</html>

Last edited by TwoD; 12-10-06 at 10:19 AM. Reason: Please use [code][/code] wrappers!
Reply With Quote
  #4 (permalink)  
Old 12-04-06, 08:57 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
please use [ code] wrappers

also: it's not that good to post the ENTIRE code. Only the part that matters is enough. You can strip down your problem to the javascript code and 1 usage example:
Code:
<script language="JavaScript">

btn1_on = new Image(); btn1_on.src = "images/nav_home.gif";
btn1_off = new Image(); btn1_off.src = "images/nav_home_onclick.gif";

btn2_on = new Image(); btn2_on.src = "images/nav_about_us.gif";
btn2_off = new Image(); btn2_off.src = "images/nav_about_us_onclick.gif";

btn3_on = new Image(); btn3_on.src = "images/nav_calendar.gif";
btn3_off = new Image(); btn3_off.src = "images/nav_calendar_onclick.gif";

btn4_on = new Image(); btn4_on.src = "images/nav_special_interest.gif";
btn4_off = new Image(); btn4_off.src = "images/nav_special_interest_onclick.gif";

btn5_on = new Image(); btn5_on.src = "images/nav_resources.gif";
btn5_off = new Image(); btn5_off.src = "images/nav_resources_onclick.gif";

btn6_on = new Image(); btn6_on.src = "images/nav_join_us.gif";
btn6_off = new Image(); btn6_off.src = "images/nav_join_us_onclick.gif";

function imageOn(name){
document.images[name].src = eval(name + '_off.src');
}

function imageOff(name){
document.images[name].src = eval(name + '_on.src');
}
</script>
<SCRIPT language=JavaScript>

var img_width = "468";
var img_height = "60";
var img_title = "Click Here";


var ad=new Array()
ad[0]='trendy_baby_ad.gif';
ad[1]='ad_2.gif';
ad[2]='ad_3.gif';


var links=new Array()
links[0]='http://www.thetrendybebe.com';
links[1]='http://www.citizensbank.com';
links[2]='http://www.ethos.com';

var xy=Math.floor(Math.random()*ad.length);
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</SCRIPT>
this also rings a certain bell: haven't you posted this question before? ow yes:
http://www.programmingtalk.com/showthread.php?t=34506

If you need more help on that topic, you don't have to start a new thread, you can simply reply to the existing one. We will tend to it anyway

I gave you a solution, or a possible solution in your other thread. Check that out, and then post what problems your having.

I'm gonna ask to merge these threads together

UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 12-04-06, 09:13 PM
aliciany aliciany is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Undreal Ed, I am new to this board and EXTREMELY rusty with my scripting. I couldn't make heads or tails of your answer. I remember vaguely that something needs to be written in the HTML code to call the script in the right place, but where and how escapes me.

aliciany
Reply With Quote
  #6 (permalink)  
Old 12-04-06, 09:16 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
instead of using:
Code:
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</SCRIPT>
use this:
Code:
document.getElementById("container").htmlText = '<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>';
and replace IMAGE AND LINK HERE with:
Code:
<div id="container"></div>
Give it a try, and post back
Good Night And Good Luck,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 12-05-06, 08:39 PM
aliciany aliciany is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
UnrealEd,

Sorry it didn't work. I got an error message that said your line of code:

'document.getElementById[...]' is null and not an object

aliciany
Reply With Quote
  #8 (permalink)  
Old 12-06-06, 09:16 AM
Shaffer Shaffer is offline
Wannabe Coder
 
Join Date: Sep 2006
Location: Israel
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
You know you can do this ALOT easier and dynamically without the bundle of script you are using. Unless this is a challenge you have taken or task you must complete I suggest you use the easy way. Would you like to know what it is?
__________________
Hello from Israel!
Reply With Quote
  #9 (permalink)  
Old 12-06-06, 11:07 AM
aliciany aliciany is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Any way to get it done would be great!

aliciany
Reply With Quote
  #10 (permalink)  
Old 12-07-06, 07:55 AM
Shaffer Shaffer is offline
Wannabe Coder
 
Join Date: Sep 2006
Location: Israel
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
By the way, you should try to add the parameter type="javascript/text" to the <script /> tags according to the w3c.
__________________
Hello from Israel!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Immediate Javascript Help Needed - Image Rotation 170Designs JavaScript 1 07-13-06 11:10 PM
Is it possible to rebuild image rotation javascript to perform similar, but at the sa RomanRusso JavaScript 1 05-05-06 01:36 PM
Image Rotation Script RTAdams89 Script Requests 4 04-01-06 06:11 PM
Random Image Rotation mikeyfaces Script Requests 0 10-09-05 01:48 PM
Image Rotation based on Date/Time Evil Jon Script Requests 2 04-01-05 08:29 PM


All times are GMT -5. The time now is 11:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.