JavaScript - Generating A Random Between 2 Numbers [help!]
1st, Hi Coding forums!
I'll get to the point, I'm a noob -.- I'm using greasemonkey for a certain website. Basically, I'm using gm to refresh the page after a certain time, I was however wondering, If I can set it to a random number between 2 specific times? The code I'm using atm is setTimeout(function() { document.location.reload(); } , 10000); I know I have to use math.random, well, I think I do. But I'm not sure how to do it between 2 certain times? So to summarise, I'm trying to refresh a page at any given random time between say 5-10 minutes. Any help is appreciated, thanks! Similar TutorialsI'm trying to find a much simpler way than this current script I am using to generate and print a random word. I don't want to have to name each word but instead just include a very large list of about 300,000 words that javascript uses to pull a random word out of. Can you please help me out?? The list of words I have is a straight list with no commas or anything. I am currently outputting to a text box, but I am looking to generate words according to users input. For example, a user wants 500 words starting with the letter "b" and is less than 5 characters long appended to the character "de." Any help would be awesome! Even a right direction. I'm also willing to pay some for such a script if need be. Thanks! Here's my code: Code: <SCRIPT LANGUAGE="JavaScript"> <!-- var NumberOfWords = 28 var words = new BuildArray(NumberOfWords) words[1] = "czarevitch" words[2] = "brightwork" words[3] = "verkrampte" words[4] = "protectrix" words[5] = "nudibranch" words[6] = "grandchild" words[7] = "newfangled" words[8] = "flugelhorn" words[9] = "mythologer" words[10] = "pluperfect" words[11] = "jellygraph" words[12] = "quickthorn" words[13] = "rottweiler" words[14] = "technician" words[15] = "cowpuncher" words[16] = "middlebrow" words[17] = "jackhammer" words[18] = "triphthong" words[19] = "wunderkind" words[20] = "dazzlement" words[21] = "jabberwock" words[22] = "witchcraft" words[23] = "pawnbroker" words[24] = "thumbprint" words[25] = "motorcycle" words[26] = "cryptogram" words[27] = "torchlight" words[28] = "bankruptcy" function BuildArray(size){ this.length = size for (var i = 1; i <= size; i++){ this[i] = null} return this } function PickRandomWord(frm) { var rnd = Math.ceil(Math.random() * NumberOfWords) // Display the word inside the text box frm.WordBox.value = words[rnd] } //--> </SCRIPT> New to JS, and not too good at it. Trying to take some prewritten code and add script that displays some random text. Having trouble with assignment. Instructions are to replace a section of the file I am given with a script element. In the script element I am suppose to declare a variable named tipNum equal to a random integer between 1 and 10 returned by the randInt() function (which I made and have shown below). Then I am suppose to use a series of document.write() methods to write the following HTML code into the page: Code: <h1>Random Tip<br />title</h1> <p>tip</p> (Where "title" is the title of the random text as generated by the tipTitle() function from a external file, and which I did not make; and "tip" is the text of the random tip as genereated by the tipText() function, which is also from the external file, and not made by me) My code for the randInt() function is Code: function randInt(lower, upper) { var size = ++(upper - lower); var randValue = Math.floor(lower + size*Math.random()); } The script I made to display the HTML code is Code: <script type="text/javascript"> var tipNum = randInt(1, 10); document.write("<h1>Random Tip<br />"+tipTitle(tipNum)+"</h1>"); document.write("<p>tipText()</p>"); </script> I am getting nothing on my page where the random text should be. Any help or advice would be great, thanks. I want a certain amount of image spots to show a certain set of images (specifically 8) in a random order every time the page is refreshed. I do not want the images to be repeated, however. The solution I came up with was to create an array and generate a number one to eight and then compare that number to the numbers previously in the array, and if it matched one that was previously generated, to generate a new number and then compare it. This continues until i have an array of the numbers 1-8 in a random order. Code: var imgs=new Array(8); for(i in imgs) { function generate() { return Math.floor(1+Math.random()*8); } var rand=generate(); function compare(i) { for(var n=i-1; n>=0; n--) { if (n<0) { imgs[i]=rand; } else { if (rand==n) { rand=generate(); compare(i); } } } } } This does not strike me as the most efficient way to go about this. If someone has a better solution, that would help a great deal. I am working on a work project that requires a 5*5 table, that will generate random letters in each cell upon button click. I have most of the coding complete with the exception of the letter generation. I am currently generating numbers, I would even be fine with having a RandBetween(and listing the 26 letters of the alphabet) at this point. Any suggestions? Code: <script type="text/javascript"> var random1, random2, random3, random4, random5, random6, random7, random8, random9, random10, random11, random12, random13, random14, random15, random16, random17, random18, random19, random20, random21, random22, random23, random24, random25; var randomArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; //generate the random characters function CreateCellData() { for (var i=0; i<randomArray.length; i++) { randomArray[i] = Math.floor(Math.random()*99 + 1); } } Hello, I need help creating a function in javascript that produces random numbers generated from a normal curve distribution with a mean and standard deviation that I can specify (and easily change). I would like only whole numbers and the ability to set reasonable maximum and minimums. Thanks, Adrian 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 hi, My script creates random numbers as shown in ; 2,5,8 1,4,5 8,9,4 5,3,3 1,1,2 2,5,8 5,3,3 ...... ...... but there are many duplications as in row1 and row6(2,5,8.)....row4 and row7 how can we modify the script so that there wont be any smilir lines.. thanks.. here is my script. PHP Code: <script> keywords1 = ["1","4","5","7","2","3"]; keywords2 = ["5", "9", "2", "10","11","6","4"]; keywords3 = ["13", "1", "3", "4", "6","7","8","2"]; var toplam=0; z1=keywords1.length z2=keywords2.length z3=keywords3.length toplam=z1*z2*z3; say=0; zaman=setInterval("yaz()",500); function yaz() { var keyword1 = keywords1[Math.floor(Math.random()*keywords1.length)]; var keyword2 = keywords2[Math.floor(Math.random()*keywords2.length)]; var keyword3 = keywords3[Math.floor(Math.random()*keywords3.length)]; say++; document.getElementById("kutu").innerHTML+=keyword1+".."+keyword2+".."+keyword3; document.getElementById("kutu").innerHTML+="<br>"; document.getElementById("kutu2").value=say; document.getElementById("kutu3").value=toplam; if(say>=toplam) dur(); } function dur() { clearInterval(zaman); } </script> <input type=button value=yazz onclick="yaz()">.. .<input type=button value=dur bakalım onclick="dur()"> ....<input type=text value="" id=kutu2 size=3> ....<input type=text value="" id=kutu3 size=3> <div id="kutu" style="position:absolute;top:5;left:250;background-color:yellow;border-style:solid;border-width:5;border-color:red;"></div> <div id="kutux1" style="position:absolute;top:5;left:350;background-color:yellow;border-style:solid;border-width:5;border-color:red;"></div> </body> </html> I would like to create a Blackjack style game for one of my high school programming classes. I can generate 3 different random numbers and use these random numbers to display an image with that number on it. How do I add the 3 separately generated numbers together to show the total?? Here is my code so far. Specifically I would like to add the myNumber1(), myNumber2() and myNumber3() results together. <html> <head> <title>Play 21</title> <script language="javascript"> function myNumber1(){ var rand_no = Math.random(); var myTotal; var ComputerTotal; rand_no = 5 * rand_no + 1; rand_no = Math.floor(rand_no); document.pic1.src = rand_no + ".gif" myNumber2(); myNumber3(); myNumber1D(); myNumber2D(); myNumber3D(); } </script> <script language="javascript"> function myNumber2(){ var rand_no2 = Math.random(); rand_no2 = 5 * rand_no2 + 1; rand_no2 = Math.floor(rand_no2); document.pic2.src = rand_no2 + ".gif" } </script> <script language="javascript"> function myNumber3(){ var rand_no3 = Math.random(); rand_no3 = 5 * rand_no3 + 1; rand_no3 = Math.floor(rand_no3); document.pic3.src = rand_no3 + ".gif" } </script> <script language="javascript"> function myNumber1D(){ var rand_no1D = Math.random(); rand_no1D = 5 * rand_no1D + 1; rand_no1D = Math.floor(rand_no1D); document.pic1D.src = rand_no1D + "D.gif" } </script> <script language="javascript"> function myNumber2D(){ var rand_no2D = Math.random(); rand_no2D = 5 * rand_no2D + 1; rand_no2D = Math.floor(rand_no2D); document.pic2D.src = rand_no2D + "D.gif" } </script> <script language="javascript"> function myNumber3D(){ var rand_no3D = Math.random(); rand_no3D = 5 * rand_no3D + 1; rand_no3D = Math.floor(rand_no3D); document.pic3D.src = rand_no3D + "D.gif" } </script> </head> <body> <table width="94%" border="1"> <tr> <td width="39%"><div align="center">First Number <img src ="1.gif" name="pic1" id=1/> </div></td> <td width="32%"><div align="center">Second Number <img src ="2.gif" name=pic2 id=2/></div></td> <td width="14%"><div align="center">Third Number <img src ="3.gif" name=pic3 id=3/> </div></td> <td width="15%"> </td> </tr> <tr> <td width="39%"><div align="center">First Number <img src ="1D.gif" name="pic1D" id=1/> </div></td> <td width="32%"><div align="center">Second Number <img src ="2D.gif" name=pic2D id=2/></div></td> <td width="14%"><div align="center">Third Number <img src ="3D.gif" name=pic3D id=3/> </div></td> <td width="15%"> </td> </tr> </tr> <tr> <td> </td> <td> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="4"><div align="center"> <input type="submit" name="Deal_Cards" id="Deal_Cards" value="Deal Cards" onClick="myNumber1()" /> </div></td> </tr> </table> </body> </html> jchudson jchudson@mts.net Hello all, I hope someone can help me with this. I have a form wich has a add/remove row button, this so the visitor can select multiple sets of data. All is fine and is being submitted via PHP. Only problem is from number 10 and up, i am getting strange random numbers in the new rows that are added in their name. Like 1111 (instead of 11), 122222 (instead of 12). And because of this, every row from 10 and up won't be send through php, giving this random effect. I can't seem to find why this is happening. Hopefully someone can help me out in this. The full form can be viewed http://www.multisearch.info/test/form_ruby_2.html The code i use for my Clone Element is Code: //clone element var clone; function cloneRow(row){ clone=row.cloneNode(true); } function addRowToTable(row){ var tbody=row.parentNode; var inputs=clone.getElementsByTagName('input'), i=0, inp; i=0; while(inp=inputs[i++]){ if(inp.type=='text'){ inp.onfocus=function(){this.value='';} } if(inp.type=='button'){ inp.value=='Add'?inp.onclick=function(){addRowToTable(this.parentNode.parentNode)}:inp.onclick=function(){removeRowFromTable(this.parentNode.parentNode)}; } } tbody.appendChild(clone); cloneRow(tbody.getElementsByTagName('tr')[tbody.getElementsByTagName('tr').length-1]); reorderNames(); } function removeRowFromTable(row){ row.parentNode.removeChild(row); reorderNames(); } function reorderNames(){ var rows=document.getElementById('tblSample').getElementsByTagName('tbody')[0].getElementsByTagName('tr'), r, i=0, el, e, j; while(r=rows[i++]){ el=r.getElementsByTagName('*'); j=0; while(e=el[j++]){ e.nodeName=='SELECT'||(e.nodeName=='INPUT'&&e.type=='text')?e.name=e.name.replace(/\d/,i):null; } } } onload=function(){ var row=document.getElementById('tblSample').getElementsByTagName('tr')[0]; cloneRow(row); } Hi all.. I've been trying to get random numbers in JS. It works when I assign fixed values, but when I want those values to come from a form, I get all the problems.. any comments on my script? Thanks. M [CODE] <script type="text/javascript"> function random() { var x=document.getElementById("text1").value;// num ingresado por el usuario var y=document.getElementById("text2").value; //var x=1; //var y=6; num=Math.floor(x + Math.random() * y); var r=document.getElementById("demo") r.innerHTML=num; } </script> [CODE] i have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads. var random = Math.floor(Math.random()*40 + 1) //sets variables for random numbers to generate var random2 = Math.floor(Math.random()*40 + 1) var random3 = Math.floor(Math.random()*40 + 1) var random4 = Math.floor(Math.random()*40 + 1) var random5 = Math.floor(Math.random()*40 + 1) var random6 = Math.floor(Math.random()*40 + 1) //create table function makeTable(lotto) document.getElementById("tableSpan").innerHTML = '<table border="1" id="lotto">'; var caption=document.getElementById('lotto').createCaption(); caption.innerHTML="JavaScript Random Numbers"; var x=document.getElementById('lotto').insertRow(0); var cell1=x.insertCell(0); var cell2=x.insertCell(1); var cell3=x.insertCell(2); var cell4=x.insertCell(3); var cell5=x.insertCell(4); var cell6=x.insertCell(5); cell1.innerHTML='<td class = "normal">'+ random +'</td>'; cell2.innerHTML='<td class = "normal">'+ random2 +'</td>'; cell3.innerHTML='<td class = "normal">'+ random3 +'</td>'; cell4.innerHTML='<td class = "normal">'+ random4 +'</td>'; cell5.innerHTML='<td class = "normal">'+ random5 +'</td>'; cell6.innerHTML='<td class = "red">'+ random6 +'</td>'; } heres the HTML file: <body onload="makeTable('lotto');"> <div id="container"> <div id="header"> <h1>Welcome</h1> </div> <div id="content"> <span id="tableSpan"></span> <input type="button" value="Re-generate Numbers" onclick="makeTable('lotto');" /> </div> { Hello! I am trying to create a javascript code in which I prompt the user for a number (an integer from 0 to 100) to search for, then search a function with the number they entered and then display whether the number was found, and if found, a location where it can be found within the list. Can you please tell me what is wrong? <html> <head> </head> <body> <script language = "javascript"> var list = new Array(200); for (var i=0; i < 200; i++){ list=Math.round(Math.random()*100) + " "; document.write(list); } var value=prompt("What is the number you are searching for? ", " "); if (list[i]==value){ {alert("Number has been found in location" +i)}; } </script> </body> </html> Thank you Sorry about the title, I didn't know what else to use to describe my problem. Basically, I'm generating a random word with a function; then I'm trying to pass this word down to another function. The problem is, when I pass the word, it changes each time (due to it being randomly generated originally). I'm only calling the function once (via button click), but I'm also calling the function in my code lower down to retrieve the returned variable; and the function seems to be running again and returning a new word from my array. Here's a snippet of my code: Code: function ranNum(){ var ranNum = Math.round(Math.random()*10); var chosenWord = wordArray[ranNum]; return chosenWord; } function makeBoxes(x){ //remove children when new word is chosen var hM = document.getElementById("hangMan"); while(hM.firstChild){ hM.removeChild(hM.firstChild); } var chosenWord = ranNum(x); var wL = chosenWord.length; //create box for length of letters in word var i = 0; for(i=0;i<wL;i++){ var cBoxes = document.createElement("div"); cBoxes.className = "letterBoxes"; cBoxes.innerHTML = chosenWord.charAt(i); hangMan.appendChild(cBoxes); } return chosenWord; } function checkLetter(y){ var chosenWord = makeBoxes(y); alert(chosenWord); } So I generate a word with one button; now I need to be able to work with said word in my checkLetter() function. The word changes however. Any help would be greatly received. 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! Hello, I have this idea, but I wouldn't want to reinvent the wheel if it's already been done. I want to generate perspective grid on canvas depending on browser window size, something like this, but without textures: http://www.123rf.com/photo_2651286_a...rspective.html Do someone of you guys know if some similar script already exists? Or at least some tips on how not to end up writing a 1000 lines script (At this point I would just drop the idea)? All thoughts appreciated. P.S. even an obscure algorithm would probably suffice, 'cause the main problem I'm struggling with is diminishing size perspective calculations Hi all, I have been checking out this web audio api app Beat Petite The thing that really interests me about it is that as the user alters the interface settings the URL changes, and all the settings can be recalled just by saving the URL (so if you make a cool drum beat you can share it with your friends by giving them the URL). I would love to be able to implement this feature on my own site but I have no idea where to start! Can anyone shed any light on how this can be done? I am not even sure if this is JavaScript that is controlling this or some other technology. Any ideas would be much appreciated. Thanks, Hulk I found this code in another thread... basically, I need to be able to display a certain image based on the page's title... for instance if the title is: Lotus 7, I need image lotus.jpg to display in an element on the page, however, if the title is Bodhi 9, I need image bodhi.jpg to display in the same element. Can someone help me implement this code? Code: var imgs = new Array(); imgs[0] = new Array(); imgs[0][0] = "Research"; imgs[0][1] = "bluetabs_01"; imgs[0][2] = "greentabs_01.gif"; imgs[1] = new Array(); imgs[1][0] = "Information" imgs[1][1] = "bluetabs_02"; imgs[1][2] = "greentabs_02.gif"; Code: var title = document.title; for (var i=0;i<imgs.length;i++){ if (title.indexOf(imgs[i][0])!=-1){ document.images[imgs[i][1]].src = imgs[i][2]; break; } } I'm new to programming, Here's my problem: I'm using a for loop to generate a list of hyperlinks for(i = 100; i < 200; i++) { var str = "link"; document.write(str.link('http://someWebsite.com/' + i +'.html')); document.write("<br />"); } so the list that is generated looks like... link link link ---------and so on until the loop is finished. My question: is it possible for each links text to be dependent on the pages title? for example instead of the the text "link", the program would follow the URL and know in the pages header was the title "Bob's website" or whatever the pages title was and would generate the list. Example: bobs website daves website rons website susies website betsys website ______________________________ Any help to differentiate the links text based on following the URL would be helpful Thank you! Ok, just to be honest this is for my assignment from my University, I have completed the whole code myself I just can't seem to get just one little thing. Code: function GenerateTables(){ var start = document.tables.start.value; var end = document.tables.end.value; var size = document.tables.size.value; for (start; start <= end; start++) { document.write("<table width='100' align='center'>") document.write("<caption><b>Table of </b>" + start + "</caption><br>") document.write("</table><br>") for (var i = 1; i <= size; i++) { document.write("<table border=1 align='center'>") document.write("<tr height=40 align='center'>") document.write("<td width=40 align='center'>" + start + "</td>") document.write("<td width=40 align='center'> * </td>") document.write("<td width=40 align='center'>" + i + "</td>") document.write("<td width=40 align='center'> = </td>") document.write("<td width=40 align='center'>" + start * i + "</td>") document.write("</tr>") document.write("</table>") } } } The function generates multiplication tables depending on the input user provides using this interface (given below). And it generates them like this (given below). Now what I want is to generate those tables sideways not downwards. Not all the tables, but it should complete one table downwards, then start the new table on its side. I can't seem to figure out anything that would make that happen, and ideas would be appreciated, thanks. Regards, Papichoolo. I CANNOT GET THIS! I created a for loop to generate a specified number of input type fields onto the page within my form. The for loop will not work! to my knowledge all the code within the for loop is correct... please help me out! Here is all the code regarding this problem... Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>History Countdown</title> <style> div#mainChart { display: none; } fieldset#main { padding: 20px 0 20px 20px; text-align: left; width: auto; min-width: 400px; } fieldset#moreInfo { padding: 20px 0 20px 20px; text-align: left; width: auto; min-width: 200px; margin: 20px; display: none; } table { margin: 0; padding: 0; } td { padding-right: 25px; } </style> <script> function enterData() { document.getElementById("moreInfo").style.display = "block"; var start = document.getElementById("startNumber").value; var end = document.getElementById("endNumber").value; var thisNumber = Math.abs(start - end); var dataFields = thisNumber + 1; alert(dataFields); setTimeout(makeFields, 500); function makeFields() { for (var i=1;i<=dataFields;i+=1){ var newNode = createElement("tr"); var newTD = createElement("td"); newTD.appendChild(document.createTextNode("Data for field " + i)); newNode.appendChild(newTD); document.getElementById("dataTable").appendChild(newNode); var newTD2 = createElement("td"); var newInput = createElement("input"); newInput.id = "data" + i; var attr1 = document.createAttribute("type"); attr1.nodeValue = "text"; newInput.setAttribute(attr1); newTD2.appendChild(newInput); newNode.appendChild(newTD2); document.getElementById("dataTable").appendChild(newNode); } } }//end makeFields function </script> </head> <body> <div id="wrapper"> <form name="dataForm" id="chartCreator"> <h1>Countdown Chart</h1><br /> <fieldset id="main"> <table> <legend>Chart Details</legend> <tr><td>Name of chart</td> <td><input name="countdownName" id="countDownName" type="text"></td> </tr> <tr><td>Start Countdown at...</td> <td><input name="BeginNumber" id="startNumber" type="text" value="1"></td> </tr> <tr><td>End Countdown at...</td> <td><input name="BeginNumber" id="endNumber" type="text" value="2011"></td> </tr> <tr><td><input type="button" value="Continue..." id="generateChart" onclick="enterData();" /></td> </tr> </table> <fieldset id="moreInfo"> <legend>Data</legend> <table id="dataTable"> <tr><td><input type="button" value="Create Chart!" id="generateChart" onclick="build();" /></td> </tr> </table> </fieldset> </fieldset> </form> </div> </body> </html> |