JavaScript - Flashcards And Random Display
Hi! I'm trying display ready made flashcards by using the example below. Now this works just fine. But I want the cards to be randomly chosen and displayed one at a time. Any ideas? I've been sitting up all night trying to figure this out on my own, but come to the conclusion that I need help, and sleep..
Code: <head> <script type="text/javascript"> window.onload= function() { var divs= document.getElementsByTagName('div'); for (var i= divs.length; i-->0;) if (divs[i].className==='question') Toggler(divs[i]); }; function Toggler(div) { var state= false; var toggled= div.nextSibling; while (toggled.nodeType!==1) toggled= toggled.nextSibling; div.onclick= function() { state= !state; toggled.style.display= state? 'block' : 'none'; }; }; </script> <style> div.flashcard { margin: 0 10px 10px 0; } div.flashcard div.question { background-color:#ddd; width: 400px; padding: 5px; cursor: hand; cursor: pointer; } div.flashcard div.answer { background-color:#eee; width: 400px; padding: 5px; display: none; } </style> </head> <body> <div id="1" class="flashcard"> <div class="question">Question goes here</div> <div class="answer">Answer goes here</div> </div> </body> </html> tag! I've tried the solution below, which successfully generates random cards, BUT the toggling just works on the first flashcard in the code Code: <div id="randomdiv1" style="display:none;"> /*inserted this as content*/ <div id="1" class="flashcard"> <div class="question">Question goes here</div> <div class="answer">Answer goes here</div> </div> </div> <div id="randomdiv2" style="display:none;"> [content for div 2] </div> <div id="randomdiv3" style="display:none;"> [content for div 3] </div> <script type="text/javascript" language="JavaScript"><!-- NumberOfDivsToRandomDisplay = 3; var CookieName = 'DivRamdomValueCookie'; function DisplayRandomDiv() { var r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay); if(NumberOfDivsToRandomDisplay > 1) { var ck = 0; var cookiebegin = document.cookie.indexOf(CookieName + "="); if(cookiebegin > -1) { cookiebegin += 1 + CookieName.length; cookieend = document.cookie.indexOf(";",cookiebegin); if(cookieend < cookiebegin) { cookieend = document.cookie.length; } ck = parseInt(document.cookie.substring(cookiebegin,cookieend)); } while(r == ck) { r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay); } document.cookie = CookieName + "=" + r; } for( var i=1; i<=NumberOfDivsToRandomDisplay; i++) { document.getElementById("randomdiv"+i).style.display="none"; } document.getElementById("randomdiv"+r).style.display="block"; } DisplayRandomDiv(); //--></script> I'm in an experimenting phase doing a lot of copy/paste so if this is very far out I wiill very much appreciate alternatives. Thanks!! Similar TutorialsHello, i got a problem with my following js-script. Sorry I'm a noob. I want to display several divs with math.random. 12 divs are in an array, after this I place 6 of them randomly in another array and want to display them. But it doesnt happen and I dont know why . Here is my script: Code: <html> <head> <style type="text/css"> .hidden{display:none;} </style> <script type="text/javascript"> window.onload = function () { var domelem = document.getElementById("wrap").getElementsByTagName("div"); var studis = []; for(var i =0; i < domelem.length; i++) { studis[i] = domelem[i]; } var a = []; while(a.length <= 5) { var spliced = studis.splice(Math.floor(Math.random()*studis.length), 1); a.push(spliced); } for (var i = 0; i < a.length; i++){ a[i].style.display = 'block'; } } </script> </head> <body> <div id="wrap"> <div class="hidden">content</div> <div class="hidden">content</div> <div class="hidden">content</div> <div class="hidden">content</div> <div class="hidden">content</div> ........ </div> The Problem is, that the divs are not displayed. I thought it was correct to do it like this. Please can anybody help, I dont know what to do. I would be very grateful. Hello, I have an array containing 100 different values. How would I randomly pick 25 of them for display? For now I do: PHP Code: for (var i=0; i<markers.length && i<25; i++) { html += markers[i].name + '<br />'; } Which of course returns 25 values but always in the same order which is not what I want. Thanks in advance! PS. My array could also contain only 20 values, in which case I would like the function to display the 20 values randomly sorted. Ok got a random image display and have tried to make it so once the image is displayed it is taken out of the array so it can not be viewed again untill there are no more elements in the array, problem is, it doesn't work. Have been told about shuffle, but not very keen on that. Can someone shed some light. 4 images, with accompaning links to be displayed 4 times, all unique. Code: Code: <script language="JavaScript"> function random_imglink(){ var myimages=new Array() myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif" myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif" myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg" myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif" var imagelinks=new Array() imagelinks[0]="http://www.4downdistribution.com/" imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513" imagelinks[2]="http://verdebmx.com/" imagelinks[3]="http://www.zealbmx.com/" var count; for(count=0; count<myimages.length; count++) { if (myimages.length>0) { var ry=Math.floor(Math.random()*myimages.length) document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>') if (ry>0 && ry<myimages.length-1) { myimages=concat(myimages. (0,ry-1),myimages.slice(ry+1,myimages.length-1)); imagelinks=concat(imagelinks.slice(0,ry-1),imagelinks.slice(ry+1,imagelinks.length-1)); } if (ry==0) { myimages=myimages.slice(1,myimages.length-1); imagelinks=imagelinks.slice(1,imagelinks.length-1); } if (ry==myimages.length-1) { myimages=myimages.slice(0,ry-1); imagelinks=imagelinks.slice(0,ry-1); } } } } </script> <script language="JavaScript"> random_imglink(); </script> an alternative way that also didn't work Code: function random_imglink(){ var myimages=new Array(); myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif"; myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif"; myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg"; myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif"; var imagelinks=new Array(); imagelinks[0]="http://www.4downdistribution.com/"; imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513"; imagelinks[2]="http://verdebmx.com/"; imagelinks[3]="http://www.zealbmx.com/"; var indexes = [0, 1, 2, 3]; index.sort(function (){ reutrn 0.5 - Math.random(); }); for(var count=0; count < index.length; count++) { var ry = indexes[count]; document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>'); } } Hi, I have a Javascript which I'm using to display one of four Flash SWF files randomly. These need to be actually displayed twice, so I'm basically calling the script twice. This works great aside from one thing- occasionally the same movie appears in both scripts, for example the first instance picks movie 3 of 4 and th second instance does the same. What I need is to somehow make sure that if the first instance of the script picks movie x then the second script will pick any movie EXCEPT movie x. This is the script as it stands: Code: <script language="JavaScript"> // Generate a Random Number var randomnumber = Math.round(Math.random()*3); // Select a swf and execute the corresponding function if (randomnumber == 1) {movie1();} else if (randomnumber == 2) {movie2();} else if (randomnumber == 3) {movie3();} else {movie4();} //Functions to write out the correct flash movie resource. function movie1(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/1.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/1.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie2(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/2.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/2.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie3(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/3.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/3.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie4(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/4.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/4.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } </script> I've looked for a solution to this issue, but it seems like a little different scenario than other situations. I made a system for generating friend requests on Facebook. I have a grid that is 6 x 3, for a total of 18 cells. Each cell has a picture in it, and the picture is linked to the Facebook friend request page. My problem is that since each cell is populated at random from the array, I'm getting lots of repeats. For example, some picutures are in 5 cells, and some are in none. I'm trying to figure out how to make it so that once a picture is used once in the grid, it does not get used again in the same grid. I still want every cell filled at random on each page load, I just want to prevent the repeating. Here's my current code: Code: <script type="text/javascript"> var vip_list=new Array( new Array('http://profile.ak.fbcdn.net/v225/1616/88/s1220771654_2158.jpg','http://www.facebook.com/addfriend.php?id=1220771654'), new Array('http://profile.ak.fbcdn.net/v223/1233/29/s904885342_9055.jpg','http://www.facebook.com/addfriend.php?id=904885342'), new Array('http://profile.ak.fbcdn.net/v229/1574/66/s1752031238_626.jpg','http://www.facebook.com/addfriend.php?id=1752031238'), new Array('http://profile.ak.fbcdn.net/v223/768/71/n661155042_7325.jpg','http://www.facebook.com/addfriend.php?id=661155042'), new Array('http://profile.ak.fbcdn.net/v226/732/26/n1827289885_2478.jpg','http://www.facebook.com/addfriend.php?id=1827289885'), new Array('http://profile.ak.fbcdn.net/v229/1631/70/s1425313768_1140.jpg','http://www.facebook.com/addfriend.php?id=1425313768'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1667023416'), new Array('http://profile.ak.fbcdn.net/v225/1146/29/s506485704_9532.jpg','http://www.facebook.com/addfriend.php?id=506485704'), new Array('http://profile.ak.fbcdn.net/profile6/270/32/s692160490_8745.jpg','http://www.facebook.com/addfriend.php?id=692160490'), new Array('http://profile.ak.fbcdn.net/v229/114/83/s1218176198_7375.jpg','http://www.facebook.com/addfriend.php?id=1218176198'), new Array('http://profile.ak.fbcdn.net/v226/946/4/s1470171885_4973.jpg','http://www.facebook.com/addfriend.php?id=1470171885'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1329505888'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1325496968'), new Array('http://profile.ak.fbcdn.net/v223/1546/92/s1536913202_2017.jpg','http://www.facebook.com/addfriend.php?id=1536913202'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1624715433'), new Array('http://profile.ak.fbcdn.net/v228/1282/58/s713998257_3682.jpg','http://www.facebook.com/addfriend.php?id=713998257') ); var chosen_vip=Math.floor(vip_list.length*Math.random()); var chosen_vip1=Math.floor(vip_list.length*Math.random()); var chosen_vip2=Math.floor(vip_list.length*Math.random()); var chosen_vip3=Math.floor(vip_list.length*Math.random()); var chosen_vip4=Math.floor(vip_list.length*Math.random()); var chosen_vip5=Math.floor(vip_list.length*Math.random()); var chosen_vip6=Math.floor(vip_list.length*Math.random()); var chosen_vip7=Math.floor(vip_list.length*Math.random()); var chosen_vip8=Math.floor(vip_list.length*Math.random()); var chosen_vip9=Math.floor(vip_list.length*Math.random()); var chosen_vip10=Math.floor(vip_list.length*Math.random()); var chosen_vip11=Math.floor(vip_list.length*Math.random()); var chosen_vip12=Math.floor(vip_list.length*Math.random()); var chosen_vip13=Math.floor(vip_list.length*Math.random()); var chosen_vip14=Math.floor(vip_list.length*Math.random()); var chosen_vip15=Math.floor(vip_list.length*Math.random()); var chosen_vip16=Math.floor(vip_list.length*Math.random()); var chosen_vip17=Math.floor(vip_list.length*Math.random()); document.write('<center>'); document.write('<a href="',vip_list[chosen_vip][1],'" target="_blank"><img src="',vip_list[chosen_vip][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip1][1],'" target="_blank"><img src="',vip_list[chosen_vip1][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip2][1],'" target="_blank"><img src="',vip_list[chosen_vip2][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip3][1],'" target="_blank"><img src="',vip_list[chosen_vip3][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip4][1],'" target="_blank"><img src="',vip_list[chosen_vip4][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip5][1],'" target="_blank"><img src="',vip_list[chosen_vip5][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip6][1],'" target="_blank"><img src="',vip_list[chosen_vip6][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip7][1],'" target="_blank"><img src="',vip_list[chosen_vip7][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip8][1],'" target="_blank"><img src="',vip_list[chosen_vip8][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip9][1],'" target="_blank"><img src="',vip_list[chosen_vip9][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip10][1],'" target="_blank"><img src="',vip_list[chosen_vip10][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip11][1],'" target="_blank"><img src="',vip_list[chosen_vip11][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip12][1],'" target="_blank"><img src="',vip_list[chosen_vip12][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip13][1],'" target="_blank"><img src="',vip_list[chosen_vip13][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip14][1],'" target="_blank"><img src="',vip_list[chosen_vip14][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip15][1],'" target="_blank"><img src="',vip_list[chosen_vip15][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip16][1],'" target="_blank"><img src="',vip_list[chosen_vip16][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip17][1],'" target="_blank"><img src="',vip_list[chosen_vip17][0],'" height="60" width="60"></a>'); document.write('<br>'); </script> Any suggestions? Thank you! Hi, I'm not much of a programmer, I have this script for randomly rotate a bunch of pictures. What do you change to make to change from one another, not random? Thanks Denny <script language="javascript"> var delay=5000 //set delay in miliseconds var curindex=0 var i = 0 var randomimages=new Array() randomimages[0]="...image01.jpg" randomimages[1]="...image02.jpg" randomimages[2]="...image03.jpg" randomimages[3]="...image04.jpg" randomimages[4]="...image05.jpg" randomimages[5]="...image05.jpg" var preload=new Array() for (n=0;n<randomimages.length;n++) { preload[n]=new Image() preload[n].src=randomimages[n] } i = Math.floor(Math.random()*(randomimages.length)) document.write('<img border=2 name="defaultimage" src="'+randomimages[i]+'">') function rotateimage() { if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))) { curindex=curindex==0? 1 : curindex-1 } else curindex=tempindex document.images.defaultimage.src=randomimages[curindex] } setInterval("rotateimage()",delay) </script> Dear all, Appreciate your kind guidance and help in helping me to solve the following code. I wanted to generate a set of random number on the pinpad everytime the page is being loaded. (1-9 but the number can only appear once) How do I get about doing it? Sincere Thanks CAD Code: <html> <head> <title>Testing with PinPad</title> <div align="center"> <script language="JavaScript"> document.logonForm.autocomplete='off'; function setPin(ctl) { var pinVal = document.logonForm.login_pin.value; ctlValue =cutSpaces(ctl.value); if(ctlValue=='Clear'){ document.logonForm.login_pin.value = '';} else if(ctlValue=='x') { } else { if(pinVal.length==6) { document.logonForm.pin.value = ''; } else { document.logonForm.login_pin.value = pinVal + ctlValue; } } } function cutSpaces(s) { var s1, x; x = s1 = ""; l = s.length; for(i = 0; i < l; i++) if((x = s.charAt(i)) != " ") s1+=x; return s1; } </script> <script language="javascript"> document.logonForm.login_userid.focus(); </script> </head> <form method="post" action="" name="logonForm"> <table width="550" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td> <div align="left" class="Headline1">ViA ONLINE - LOGIN WITH PIN PAD</div><hr> </td> </tr> </table> <div align="center" class="Error"><br></div> </td> </tr> </table> <table width="550" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="393"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="42%"> <div align="left">CUSTOMER NUMBER</div> </td> <td width="58%"> <div align="left"><input type="text" name="login_userid" class="TopTextbox" value=""></div> </td> </tr> <tr> <td width="42%"> <div align="left">PASSWORD</div> </td> <td width="58%"> <div align="left"><input type="password" name="login_password" class="TopTextbox" value=""></div> </td> </tr> <tr> <td width="42%"> <div align="left">PIN</div> </td> <td width="58%"> <div align="left"> <input type="password" name="login_pin" class="pin_textbox" value="" readonly="readonly" > <br>Enter using Pin Pad </div> </td> </tr> <tr> <td></td> <td><div align="left"><input type="submit" name="login_submit" class="Button1" value="LOGIN"> </div></td> </tr> </table> </td> <td width="157"><div align="left"> <table width="105" border="0" align="right" cellpadding="1" cellspacing="1" bgcolor="#C2C2C2"> <tbody> <tr> <td> <input name="firstbutton" value="pinpad_0" type="hidden"> <table width="100%" height="112" border="0" cellpadding="1" cellspacing="1"><tbody><tr><td colspan="3"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td border="1" colspan="3" id="titleBar" style="cursor: move;" class="pinpad_key" bgcolor="#246584" nowrap="nowrap"> <center> <font color="white"><b> Pin Pad</b></font></center> </td> </tr> </tbody> </table> </td> </tr> <tr> <td height="22" align="center"> <input class="pinpad" tabindex="4" name="pinpad_0" value='5' onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_6" value="3" onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_5" value="4" onclick="setPin(this)" type="button"> </td> </tr> <tr> <td height="22" align="center"> <input class="pinpad" tabindex="4" name="pinpad_7" value="6" onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_4" value="1" onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_8" value="9" onclick="setPin(this)" type="button"> </td> </tr> <tr><td height="22" align="center"> <input class="pinpad" tabindex="4" name="pinpad_9" value="2" onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_1" value="7" onclick="setPin(this)" type="button"> </td> <td align="center"> <input class="pinpad" tabindex="4" name="pinpad_2" value="8" onclick="setPin(this)" type="button"> </td> </tr> <tr><td height="22" align="center"> <input class="pinpad" tabindex="4" name="pinpad_3" value="0" onclick="javascript:setPin(this)" type="button"> </td> <td colspan="2" align="center"> <input class="pinpad_clear" tabindex="4" name="pinpad_clear" value="Clear" onclick="setPin(this)" type="button"> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> </td> </tr> </table> <table width="550" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td><br><hr> </form> </html> Alright, I need a little help with my javascript. I'm a bit of a novice when it comes to programming so I apologize if this appears trivial. I have an element ID that begins with bb + a randomized number between 1-100,000. This number changes after every action so what I need is a way to retrieve this new value each time and implement it into my code. I can view the number using firebug but I need a way to automate this process. Do any of you have some advice about how I could approach this problem? I can generate a random number between 1 and 9, ( var rand_no = Math.floor( 1 + Math.random() * 9 ); ) but I want to add that random number to a value that is enterred into an inputbox and get a total. How can I do this using Javascript and put the result into a hidden field. I will also need to use that same random number in another place on another form . Thanks This is quite easy yet hard. I'm trying to apply something in my forums, where a member could post something let's say: "Hi, I am number [random]1, 6[/random]" And what would happen is that, a number from 1 to 6 would be the content, for example, it would be: "Hi, I am number 3" But if you refresh the page, it would still be the same number. Like it won't be randomized again. So how do I make a javascript/html code that would make a one time number randomizer. Hi, I have this bit of java code that puts a random/unique number in a field on my web page: <html> <head> </head> <body> <form> <input type="text" name="MyField" /> </form> <script langueage="javascript" type="text/javascript"> var d = new Date(); var tm = d.getTime(); document.getElementsByName('MyField')[0].value=tm; </script> </body> </html> My problem is that I want to limit the number to just 6 digits. Is this possible? Any help would be much appreciated Thank you Dave I recently decided to organize my bags on http://www.coach-bag.org/category-1-...+Handbags.html - I labelled all the boxes, making sure each box had only one purse in it's dustbag and organized by season. I have 14 at the moment - 4 for Spring/Summer and 10 for Fall/Winter. I actually (OK, this is going to sound oh-so-anal) did up a schedule by week and purse and will change over every Sunday morning. I did the schedule until the end of January and each purse only gets into rotation twice - that's not very much and I hate the idea of things not getting adequate usage. And it really got me thinking as to what else I really need - but then again, who needs 14 purses, right? We all know this isn't about need. So that got me thinking about something mentioned in another thread. I have a price point in my head that I'm not comfortable going over per bag and it's $400. I had a brief moment when I considered the floral Sophia, but once I saw the modelling shots and figured out she was too big, I dismissed it and was a little relieved to do so. But with 14 bags not getting into rotation that often, I'm wondering if I should change my mindset to buy 2-3 more expensive bags per year rather than what I did in this first 14 months of Coach collecting - which was buy 14 (plus all the wallets, scarves, keyfobs and other goodies). If I do that again this year, that means I could be close to 30 purses, and honestly, I'm not comfortable with that many bags - not from the financial standpoint - just the usage or lack thereof standpoint. It seems like a lot of you ladies do spend the big bucks on bags - and lots of them - and that's great. I'm not independently wealthy, and I refuse to run a credit card balance for purses, so I only buy what I can afford and usually wait for PCE. And I guess I love a deal more than I love any individual purse, so it will really be a change in mind set for me to pay maybe $1000 for a bag maybe 2-3 times a year instead of what I've done this past 14 months where I bought 14 bags - mostly at 25%, 40% or outlet pricing. I know for some of you ladies who have DOZENS of bags, my 14 must seem minuscule and you probably think I'm nuts for thinking so hard about it - but I need to find the right balance, and I guess I'm just trying to sort that out. Does anyone else think so hard about this silly little topic or is it just me? Thanks for letting me unload my thoughts here!! hey. im working on a facebook app.. this is what i got so far. PHP Code: <script language="JavaScript"> <!-- var theImages = new Array() theImages[0] = "http://img688.imageshack.us/img688/4787/logo1tq.jpg" theImages[1] = "http://img641.imageshack.us/img641/8292/logo2yex.jpg" theImages[2] = "http://img864.imageshack.us/img864/4097/logo3ik.jpg" theImages[3] = "http://img543.imageshack.us/img543/9046/logo4pu.jpg" theImages[4] = "http://img21.imageshack.us/img21/2567/logo5q.jpg" theImages[5] = "http://img842.imageshack.us/img842/696/logo6o.jpg" theImages[6] = "http://img85.imageshack.us/img85/7831/logo7k.jpg" var j = 0 var p = theImages.length; var preBuffer = new Array() for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1)); function showImage(){ document.write('<img src="'+theImages[whichImage]+'">'); } //--> </script> <script language="JavaScript"> <!-- showImage(); //--> </script> now i want that the app posts the random image automaticlly to the useres timeline.. for example: if the random image is theImages [3] then it should post the image theimage [3] to the users timeline.. i see alot of facebook apps doing this.. thanks in advance I need to write something like this: http://justsheri.com/webscripting/wsassignment/1049950/ If you look at the code there is 52 of these <img src = './images/blank1.png' onClick='clickCard("qh",0)'/> where clickcard("numchanges", increments by 1) how is this done? Thanks Danny Hello! I have an array of strings, like this: var strings= [ "car", "black", "word", "small", "paper", "doom", "elemental", "sword", "mouse" ]; Now i got a function newgame() and i wanna display random word from this array in rectangles gray styled... Here is the problem. I can make to display random words, but i dont know how i make this words with the css style together - rectangels around a char. But the words are different length so i dunno? When i press newgame button, i want for example to random a word from the array: for example word "paper" then i want it to be displayed like this [p] [a] [p] [e] [r], where [ ] are rectangels around the chars ( with the css style, like this: border: 1px solid #000; width:10px; background-color:gray; text-align:justify; padding: 5px 10px; i make a gray rectangle border around the char, but how can i make it work with random words? How can i make it work? Any help please! Hi i have set up a token key to give me some extra protection against direct url access to the page but i wanted to make it random. at first i used session token but it is not set until after a page refresh on login so this has to be its own deal.. i have found several javascript random codes but how to i pass that value to the window call.. here is the window call.. as you can see right know i have it hard coded as one token all the time. i just need it random and then sha1 (or md5) Code: function url_chat(){ chatwindow = window.open("<?=$CONST_MY_ROOT?>/mychat/chat/index.php?tok=0ed61bdd3a8a86f39e6b4abd01ba4e3649d0ec1c", "chatwindow", "location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=950,height=550"); } i could use this i guess but i dont know how to get that value to the window call above. Code: document.write(Math.floor(Math.random()*999999999999999999)); I've started studying JavaScript recently. The following simple scenario from the Russian textbook cannot be implemented on my PC. Code: <HTML> <HEAD> <TITLE>Object Math Example</TITLE> </HEAD> <BODY> <h1>Object Math Example</h1> <p>Насколько случайны числа, полученные генератором случайных чисел? Подсчитаем среднее 5000 случайных чисел.</p> <SCRIPT LANGUAGE="JavaScript"> total = 0; for (i = 0; i<5000; i++) { num = Math.random(); total += num; document.status = "Generated " + i + " numbers"; } average = total / 5000; average = Math.round(average * 1000 / 1000); document.write("<h2>" arithmetic mean of random numbers + average + "</h2>"); </SCRIPT> </BODY> </HTML> I just typed the script char by char. I use Firefox browser, v.3.5.7. The error console does not display any mistakes. Please, explain me what is wrong in the code. I have a text file(quotes.txt) with 35+ quotations, separated by a single line break. Is it possible for a DIV to display a random quotation from quotes.txt each time the user visit my home page?
Hey I'm somewhat new to the javascript world because 95% of my website is HTML so, if you will, I need help writing the javascript for a Random Question Generator...basicly all I have is Code: <script type="text/javascript"> var Q = new Array() Q[1] = "What is your favorite color?"; Q[2] = "What is your favorite animal?"; Q[3] = "What is your favorite place?"; </script> In the real one, there will be about 20 questions and I will need it to choose a quetion randomly out of the 20. As I said i am a beginer so as simple as possible would be great. Thank You for your help in advance Hi. Now I know this is a fairly easy task, but I need to show the random div from a selection of 10 which all have the same class. I am not able to do this using unique IDs as the divs will be created by the end user as a repeating region from Adobe contribute. So I'll have a list looking something like the following but I only want one to show. Any ideas? Code: <div class="mydiv">Line Number One</div> <div class="mydiv">Line Number Two</div> <div class="mydiv">Line Number Three</div> <div class="mydiv">Line Number Four</div> <div class="mydiv">Line Number Five</div> <div class="mydiv">Line Number Six</div> <div class="mydiv">Line Number Seven</div> <div class="mydiv">Line Number Eight</div> <div class="mydiv">Line Number Nine</div> <div class="mydiv">Line Number Ten</div> |