Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-04-2008, 04:35 PM   PM User | #1
jrripi
New to the CF scene

 
Join Date: Dec 2008
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jrripi is an unknown quantity at this point
Lightbulb Help needed to merge 2 scripts.

I need help to merge 2 scripts which are the following:


1 - random picture on the page. Simple as that, I've got a script that loads a random picture from a selection of 4 each time the page load or refresh.

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()

myimages[1]="ads/lftnp.jpg"
myimages[2]="ads/mrffg.jpg"
myimages[3]="ads/nac1320.jpg"
myimages[3]="ads/nac1540.jpg"

var ry=Math.floor(Math.random()*myimages.length)

if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}

random_imglink()

</script>


2 - pop up window comes up when click on pic. Gives a zoom effect and you can choose the size of the window.

<a href="page.htm" target="popup">
<img src="ads/lftnp.jpg" onClick="wopen(page.htm', 'popup', 650, 500)">


finally, what I want is to load the page, then comes up the random image and when i click on this image, the pop up window comes and it zooms the image and shows info as well.

Can anybody help me???

Thanks in advance
jrripi is offline   Reply With Quote
Old 12-04-2008, 06:55 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by jrripi View Post
I need help to merge 2 scripts which are the following:

1 - random picture on the page. Simple as that, I've got a script that loads a random picture from a selection of 4 each time the page load or refresh.

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()
myimages[1]="ads/lftnp.jpg"
myimages[2]="ads/mrffg.jpg"
myimages[3]="ads/nac1320.jpg"
myimages[3]="ads/nac1540.jpg"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}

random_imglink()
</script>

Quite a few errors here.

myimages[3]="ads/nac1320.jpg";
myimages[3]="ads/nac1540.jpg";

var ry=Math.ceil(Math.random()*myimages.length);
document.write('<img src= ' + myimages[ry] + 'border=0>');
}

<script language="JavaScript"> is deprecated. Use <script type = "text/javascript"> instead.


Following protracted negotiations we have come to an arrangement with the banks under which we have agreed not to supply goods to our customers on credit. For their part the banks have agreed not to sell computer equipment.
Philip M is offline   Reply With Quote
Old 12-04-2008, 10:38 PM   PM User | #3
jrripi
New to the CF scene

 
Join Date: Dec 2008
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jrripi is an unknown quantity at this point
sorry about the mistakes... it was myimages[4]="ads/nac1540.jpg"; instead of [3]. I've changed the javascript bit as well. thanks for that
anyway, both work fine but still need help to merge them.
jrripi is offline   Reply With Quote
Old 12-05-2008, 08:11 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
is not random. Math.floor will generate 0,1,2,3 (never 4), and if ry == 0 then ry becomes 1, so you will get only 1,2 and 3 with twice as many 1's as 2's or 3's.

Use instead:-

Code:
var ry = Math.ceil(Math.random()*myimages.length);
document.write('<img src= ' + myimages[ry] + 'border=0>');
}

I don't understand what you mean by "merge" scripts. I see only one script.
But you "merge" two scripts simply by putting them both within the sme <script> tags.

<script type = "text/javascript">
function one() {
// content of function one
}
function two() {
//content of function two
}
</script>


A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Philip M is offline   Reply With Quote
Old 12-05-2008, 11:16 AM   PM User | #5
jrripi
New to the CF scene

 
Join Date: Dec 2008
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jrripi is an unknown quantity at this point
right, what i'm trying to achieve is to load the picture, then I want to be able to click on this pic and zoom it. is it possible?
jrripi is offline   Reply With Quote
Old 12-05-2008, 11:34 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Try this:-

http://javascript.about.com/library/blzoom.htm
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
jrripi (12-05-2008)
Reply

Bookmarks

Tags
image, load, popup, random, zoom

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:01 AM.


Advertisement
Log in to turn off these ads.