![]() |
How to randomize pics for a quiz
Hi, I need to randomize some pics of flags for a quiz.
I'm kinda new to jQuery and can't figure out how to do this. Any help would be appreciated. <form action="#" method="POST" id="myform" name="myform"> <!-- The form --> <img class="flag" src="Flaggor/sveriges-flagga.png" alt="sverige"/> <!-- The diff.. flags --> <img class="flag" src="Flaggor/usas-flagga.png" alt="usa"/> <img class="flag" src="Flaggor/armeniens-flagga.png" alt="armenien" /> <input type="text" id="answer" name="answer"> <input type="button" id="send" value="Answer"> </form> <div class="score"> <p>Score:</p><br/> <input type="text" name="points" id="points" readonly="readonly" class="knapp"/> </div> <p id="result"></p> <script> var score = 0; // Holds the score $().ready(function() { $("#send").live("click",function() { var answer = $("#answer"); // Holds the answer value if(answer.val() == $(".flag:visible").attr("alt")) { // Shows flag $("#result").html("ok"); // If the answer is correct }else { $("#result").html("fel"); // If the answer is wrong } }); changeFlag(); function changeFlag() { var antalFlags = $(".flag").size(); // The number of flags var slumpad = 0; $(".flag").eq(slumpad).show(); // This is the part I can't figure out } }); </script> |
You shouldn't use the right names for your flag images nor for the alt attribute. Too easy to get the info on them. Use numbers instead. Than in javascript:
Code:
<script type='text/javascript'> |
| All times are GMT +1. The time now is 04:06 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.