JavaScript - Help With Listing Random Shuffle
is there a way to take my random shuffle script that displays the array like this
red, yellow, blue, green, black, grey and make it so that it would list them like this red yellow blue green black grey Code: <script type="text/javascript"> function myFunction() { document.getElementById("demo").style.display="block"; var myarray=["red","blue", "yellow", "green","black", "grey"] myarray.sort(function() {return 0.5 - Math.random()}) var x=document.getElementById("demo").innerHTML=myarray; var t=setTimeout(alertMsg,10000); } function alertMsg() { document.getElementById("demo").style.display="none"; } </script> <button onclick="myFunction()">Twister Drill</button> <font size="5" color="white"> <p id="demo"><br/></p> </font> Similar Tutorialsbasically what i want to do is this array[0] = 'hello'; array[1] = 'world'; array[2] = 'foo'; array[3] = 'bar'; delete array[1]; array.fillindex() /* new array value array[0] = 'hello'; array[1] = 'foo'; array[2] = 'bar'; notice how the key values shifted them self to compensate for the missing value. /* 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! OKay, I preface this with : "I am not new to code, but have only limited experience with JS." That said, I want to use JS to shuffle elements on a page. Not randomize them (as iPods have redefined the word shuffle.). For example, I have divs A B C D E. When you visit the page they are in this order: A B C D E when you click the button for "E" I want it to come to the front. Causing the display to be: E A B C D If you then clicked the button for "B" it would end up: B E A C D I hope thats clear enough, its a difficult concept to articulate. So, depending on the order in which the user clicks the buttons, the stack is shuffled. Now, I've successfully been able to 1) set them in the page using CSS in a stack with zIndex. So, when first visiting the page they have a zIndex of A=z5 B=z4 C=z3 etc. 2) I've used the following code on a button to bring to front when clicked. Code: <input type="image" src="A Image" alt="A alt TXT" value="Change A's zIndex" onclick="document.getElementById('A').style.zIndex='6';" > This will bring any of the divs to the front when clicked. But say I click B, then C. Since this function is assigning a specific zIndex they wont overlap anymore. I think what I need is some sort of add 5 to zIndex function. (Has to be 5 in the event that the item you click is on the bottom of the stack of 5) So far I've tried: Code: <input type="image" src="A Image" alt="A alt TXT" value="Change A's zIndex" onclick="document.getElementById('A').style.zIndex=parseInt(k.zIndex) + 1;" > and Code: <input type="image" src="A Image" alt="A alt TXT" value="Change A's zIndex" onclick="document.getElementById('A').style.zIndex='z++';" > I imagine that first one is way off base, but I really thought the second one would work. Found it while searching here. If someone could point me in the right direction, or better yet EXPLICITLY explain what to do, I'd be forever indebted. Thanks. Hi friends, I am collecting and selling football stickers. Yes, World Cup 2010 stickers. The album have 640 distinct numbers. Everytime I receive a list of that stickers to buy by the user I would need ckeck out the price list because some stickers have different price from another. For example Stickers numbers: 00, 000, 1, 2, 3, 4, 5 and 29 costs 3,00. The stickers number 31, 50, 69, 88, 107, 126, 202, 411, 392, 544 and 637 costs = 1,00. The stickers 30, 49, 68, 87, 106, 125 costs 0,25 The sticker from 32 to 48 51 to 67 70 to 86 89 to 105 (and so on) costs 0,25 I would be glad if someone could help me for building a script which read from a textarea numbers contents and create a "short report" with the stickers numbers followed by its price and total sum. Bob Kuspe Hello all, I will start off by saying that i have little javascript knowledge. Ok, now that is out of the way, lol, I want to make a program or firefox extension or something to that nature that will build a Web Server Directory Index by scanning the server for all files and displaying them like this: I don't know where to start, or if javascript is capable of doing this. (if not could you suggest a language better equipped to do this? ) The reason for such a project is for my own personal security reasons. *gets on soap box* I want to know exactly what is going on behind a website before i let it run a bunch of code that could potentially harm my computer (i listen to security now, and i know how bad some Javascript can be) and if i am going to a website i don't know, i wanna scan, and see for myself if there is malicious code running. Now i know what your thinking... "hey kam... there is such a thing as a firewall / virus protection" but i am the kind of guy that want's to see for myself instead of trusting someone else program to tell me what is good and bad.... *gets down from soap box* any help would be absolutely amazing. Thx in advance, Kam Okay first things first. Firebug this website http://www.locksmith.com/ You will see that they have a script in the head tag. That script is: Quote: <script class="yext-synd-74qWXpBkYak="> (function () { var el = document.createElement('script'); el.async = true; el.src = '//s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=&latitude=&longitude='; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(el); })(); </script> They also have a form. That form is: Quote: <form title="Enter your zip and find a qualified, local locksmith" action="results.asp" method="POST"> <p><font style="font-size: 19px; font-weight: 700">FIND A LOCKSMITH</font> <input type="text" value="14646" style="font-family: Arial; font-size: 22px; color: #666666; font-weight:bold;" onclick="this.value=''" size="5" name="zip"> <input type="image" style="position: relative; top:5px" name="B1" src="images/smallgo2.jpg"> </p> </form> When you enter your zip code into that form, I think it is passed to the el.src variable as a parsed string and sent to s.yext-listings.com/ like this: //s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=INSERT_ZIP_CODE_PASSED_FROM_THE_FORM_HERE&latitude=&longitu de= When you click the submit button on the form with an input zip code, it takes you to a page where there is a huge DIV block with this script executing inside it: Quote: <script class="yext-synd-74qWXpBkYak="> (function () { var el = document.createElement('script'); el.async = true; el.src = '//s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=33405&latitude=&longitude='; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(el); })(); </script> Well the result on the second page is a listing pulled from a database and laid out in the second page in a DIV block. My question! How do I emulate this on my website? I have the Yext service. I have been on the phone with the company for over a week now and I cant get any technical support on the integration. Apparently they are having a lot of lay offs and technical support is unavailable. I am assuming that I need to build a form in HTML and have it pass the zip code to that JavaScript snippet somehow? I also want to know how the JavaScript on the second page renders a listing result from that passed form value? Thank you so much for the help in advance. I know you guys can figure this out before I do. hello recently i finally managed to make a working shopping cart system, in that i can add as many items as i want and it will work, all using cookies. Then i have another page, the cart which reads the cookie entry made with each demo purchase, then using a while loop lists these items, the problem i am having, is that when i add the textbox which would hold the value of the quantity, it is put out on the next line down, instead of next to the text which i find quite annoying. Also i would like to know how i can add a button next to the textbox, for updating the quantity, also ide like to know how i could access that button, or have it do something, since it wouldnt be prewritten. any help would be greatly apreciated. here is a zip file containing the html files of the customizable purchase page, and the new shopping cart. be sure to refresh the page before trying to use the first page, so it establishes the counter cookie. 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> 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?
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 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> 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! 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. 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 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 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 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 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? |