Search the Legacy Support Archive (up to v2020)
  1. Read-only archive (2005–2024). Posting is closed. Need help with MediaLab or DirectRT 2027? Email service@empirisoft.com.

    All words · “exact phrase” · -leave out

    Advanced search

Choosing a file at random

  1. #1

    Choosing a file at random

    In my study, I'm having the participants give a scale rating of four different fictional people ("Rate how you feel about Rachel from a scale of 1-7") and I'd like all four of the people to be on the same screen (so it looks like a multiple-choice test one one screen). I also need the four people to be listed in random order so we don't get order effects when the subjects rate each person. What is the best way to do this? My study is in MediaLab and I found that I could only have them all on the same page by using html, but how can I get the four people to be randomized within that page? Make all the possible orders, 16 files, and somehow have the program randomly pull out one of them?

    Thanks so much!

  2. #2
    jarvis24 Blair Jarvis, Administrator
    Found this at:

    http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22928024.html


    I have table on a web page that is displaying 7 different images, what I need to do is to somehow randomize the position of where each image is displayed within the table each time the page loads so that there is not one preference.

    I need the 7 images to appear on the page at all times, I've had a scout around the web for a script but haven't found one that displays the 7 seven images each time.

    this should work:

    <html xmlns="<a href="http://www.w3.org/1999/xhtml" rel="nofollow">http://www.w3.org/1999/xhtml</a>">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Randomize Images Location</title>
    <style type="text/css">
    <!--
    .style1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
    }
    -->
    </style>
    <script type="text/javascript">
    var imgs = new Array();
    imgs.push("Image1.jpg");
    imgs.push("Image2.jpg");
    imgs.push("Image3.jpg");
    imgs.push("Image4.jpg");
    imgs.push("Image5.jpg");
    imgs.push("Image6.jpg");
    imgs.push("Image7.jpg");

    function rndmImg(root)
    {
    var tmpArry = imgs.concat();
    var pics = root.getElementsByTagName("img");
    var len = imgs.length;
    for(var i=0; i<len; i++)
    {
    var rnd = Math.floor(Math.random()*tmpArry.length);
    pics.src = tmpArry.splice(rnd,1);
    }
    }
    </script>
    </head>

    <body onload="rndmImg(document.getElementsByTagName('table')[0]);">
    Randomize Images Location

    <table width="600" border="1">
    <tr>
    <th scope="col"><a href="http://www.google.com/" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><a href="http://images.google.com/imghp?hl=en&tab=wi" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><a href="http://video.google.com/?hl=en&tab=iv" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><a href="http://news.google.com/nwshp?tab=vn&hl=en" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><a href="http://maps.google.com/maps?tab=nl&hl=en" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><a href="http://mail.google.com/mail/?tab=lm" rel="nofollow"><img width="120" height="92" border="0" /></a></th>
    <th scope="col"><img src="Image7.jpg" width="120" height="92" /></th>
    </tr>
    </table>
     

    </body>

    </html>


    Excellent thanks basicinstinct works a charm.


    Haven't tried it but maybe it's a start. If you get it working it would be great if you could zip and post a sample!