Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,985
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,985
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,985
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts

  • Users who have thanked Philip M for this post:

    jrripi (12-05-2008)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •