Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: trying to find a script for a long time

  1. #1
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trying to find a script for a long time

    Hello

    I'm trying to find a random images javascript.

    what i want to do ,is to take a deck of 78 card and put it in vertical table,so that each time i will refreash the page it will show me 3 different images,without repeating it self.

    how could i make it possible?

    thank you.

    ito

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Doesn't sound all that involved, is this for a game? Here is a neat blackjack script:

    http://catcode.com/cardgame/sb21.html
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    This should work, use as many 'cards' as you like:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    var check=[];
    
    function populate(){
    var cards=[];
    cards[0]="photo1.jpg"
    cards[1]="photo2.jpg"
    cards[2]="photo3.jpg"
    cards[3]="photo4.jpg"
    cards[4]="photo5.jpg"
    cards[5]="photo6.jpg"
    cards[6]="photo8.jpg"
    cards[7]="photo9.jpg"
    
    cards.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
    
    for (var i_tem = 0; i_tem < 3; i_tem++){
    cards[i_tem]=check[i_tem]&&cards[i_tem]==check[i_tem]? cards[i_tem+3] : cards[i_tem];
    document.getElementById('layout').rows[i_tem].cells[0].innerHTML='<img src="'+cards[i_tem]+'">';
    }
    check=[cards[0], cards[1], cards[2]];
    }
    onload=populate;
    </script>
    </head>
    <body>
    <input type="button" value="deal" onclick="populate();">
    <table id="layout">
    <tr>
        <td></td>
    </tr>
    <tr>
        <td></td>
    </tr>
    <tr>
        <td></td>
    </tr>
    </table>
    </body>
    </html>
    Notes: If you want to avoid repeat cards in any position when the page is repeatedly refreshed, cookies would need to be used. If you use the deal button, there will be no repeats.

    Also: If you like, you may skip -

    Code:
    onload=populate;
    and simply hard code the beginning images for the page into their table cells (<td>'s).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks,but some thing i dont know...

    first, i would like to thank you all.

    because i'm not a pro ,sevsral things i dont know how to do with the long code:

    1.where should i put the cards?
    2.if there is a need to put the http://www.... of the cards ?
    2.where shuold i put the source/root/directory of the cards in this code?
    3.i was wrong with the position of the card , and i need them to be in horizonal view.

    ito

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    1.where should i put the cards?

    Code:
    cards[0]="photo1.jpg"
    cards[1]="photo2.jpg"
    cards[2]="photo3.jpg"
    cards[3]="photo4.jpg"
    cards[4]="photo5.jpg"
    cards[5]="photo6.jpg"
    cards[6]="photo8.jpg"
    cards[7]="photo9.jpg"
    2.if there is a need to put the http://www.... of the cards ?
    2.where shuold i put the source/root/directory of the cards in this code?

    Code:
    cards[0]="http://www.somedomain.com/cardimages/photo1.jpg"
    3.i was wrong with the position of the card , and i need them to be in horizonal view.

    Change:

    Code:
    document.getElementById('layout').rows[i_tem].cells[0].innerHTML='<img src="'+cards[i_tem]+'">';
    to:

    Code:
    document.getElementById('layout').rows[0].cells[i_tem].innerHTML='<img src="'+cards[i_tem]+'">';
    And change:

    HTML Code:
    <table id="layout">
    <tr>
        <td></td>
    </tr>
    <tr>
        <td></td>
    </tr>
    <tr>
        <td></td>
    </tr>
    </table>
    to:

    HTML Code:
    <table id="layout">
    <tr>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </table>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jhon you ar great!!! thanks alot- just one little thing

    all works great! just a one more thing...

    i would like the button to be below the pictures- could you help me with this one?

    again ,thanks a lot .

    ito
    Last edited by ito; 08-27-2006 at 01:23 PM.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Just put it there:

    HTML Code:
    <body>
    <table id="layout">
    <tr>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </table>
    <input type="button" value="deal" onclick="populate();">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks jhon again.

    is it o.k to ask more? please tell me if so.

    if its o.k with you:

    is it possible to add colum or something, so that i could add for each card its own name for example?

    in other word, when i push the button, 3 random card apears with their specific name below?

    i have to say that you help me a lot.
    i appreciate your patience, its not so obvious to me.

    thank you.

    ito

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    .cent td {
    text-align:center;
    }
    </style>
    <script type="text/javascript">
    var check=[];
    
    function populate(){
    var ims, txt, cards=[];
    cards[0]=["photo1.jpg", "card1 name"];
    cards[1]=["photo2.jpg", "card2 name"];
    cards[2]=["photo3.jpg", "card3 name"];
    cards[3]=["photo4.jpg", "card4 name"];
    cards[4]=["photo5.jpg", "card5 name"];
    cards[5]=["photo6.jpg", "card6 name"];
    cards[6]=["photo7.jpg", "card7 name"];
    cards[7]=["photo8.jpg", "card8 name"];
    
    cards.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
    
    for (var i_tem = 0; i_tem < 3; i_tem++){
    if (check[i_tem]&&cards[i_tem][1]==check[i_tem]){
    ims=cards[i_tem+3][0];
    txt=cards[i_tem+3][1];
    }
    else {
    ims=cards[i_tem][0];
    txt=cards[i_tem][1];
    }
    document.getElementById('layout').rows[0].cells[i_tem].innerHTML='<img src="'+ims+'">';
    document.getElementById('layout').rows[1].cells[i_tem].innerHTML=txt;
    check[i_tem]=txt;
    }
    }
    onload=populate;
    </script>
    </head>
    <body>
    <input type="button" value="deal" onclick="populate();">
    <table id="layout">
    <tr>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr class="cent">
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </table>
    </body>
    </html>
    Note: Where it has:

    card1 name

    and similar, put the actual name for each card.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    basicly,it works well ,but yet ,there is a problem.

    the button is shown below.

    when i'm trying to put the part of the code that you gave me, tha page shows an error.

    why its going wrong?

Bookmarks

Posting Permissions

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