JavaScript - Creating Unique Random Numbers
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> Similar TutorialsHello! 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 Hi i'm trying to make a unique random number function but i''m stuck in an infinite loop here is what ive been trying below. basically i would like the output to be VolvoSaabBMW in a random order and it should NEVER be VolvoVolvoBMW or anything of the likes, each array item can should only be used once basically. Thanks for any help at all! Code: <html> <body> <script type="text/javascript"> var mycars = new Array(); mycars[0] = "Saab"; mycars[1] = "Volvo"; mycars[2] = "BMW"; var uniquerand = new Array(); var c = 0; function randno(arrayname) { var i; var b = 0; var randomnumber=Math.floor(Math.random()*arrayname.length); if(c == 1) { while (b<1) { for (i=0;i<uniquerand.length;i++) { if(uniquerand[i] != randomnumber) { document.write(mycars[randomnumber]); uniquerand.push = randomnumber; b = 1; } } } } else { randomnumber=Math.floor(Math.random()*arrayname.length); uniquerand.push = randomnumber; document.write(mycars[randomnumber]); c=1; } } randno(mycars); randno(mycars); randno(mycars); </script> </body> </html> 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 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! 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 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 (I also posted this on stackoverflow, but haven't had any replies.) I have a script that sends a POST to a php file, and gets a new integer (primary key). Then the script creates 3 new divs, with that ID included in them as an attribute. Now, I need to be able to grab the ID and give it back to PHP when the user updates it. (It's currently a div, but later it will be an editable form.) I was going to do this by creating a button in the same script that I use to create the divs, bearing the same integer and calling a function. The problem with this concept, is that I have no idea how to create a Unique variable to pass along to the function, so it knows which number to look at. Obviously, if I have only one variable that gets overwritten with each new entry - after all of the rows load, only the last row will have a variable that matches its id. Another option is to find the value of all attributes that bear the name data-integer-question and pass its number/integer to a function, when the user does something like keyup enter. However, I have no idea how to do that. obj.returnIntJson holds the integer that I've been talking about, which changes for each row. rowNumberObj.qarowcontainer is just a reference for the parent div, which doesn't get edited by the user - you can ignore it. The script gives a result like this: <div id="questioncolumn" class="questionColumnCSS" data-integer-question="701"></div> Suggestions on how to proceed? Here's the code for one of the divs, Thanks. PHP Code: qaRowQuestion = document.createElement('div'); qaRowQuestion.setAttribute('id', "questioncolumn"); qaRowQuestion.setAttribute('data-integer-question', obj.returnIntJson); qaRowQuestion.setAttribute('class',"questionColumnCSS"); qaRowQuestionParent = document.getElementById(rowNumberObj.qarowcontainer); qaRowQuestionParent.appendChild(qaRowQuestion); 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> { ok, so I can make an object, I can also make a new instance of that object and have it running around the screen at the same time. What I'm a bit confused about is how to go about things when I want X number of these objects. So instead of making objects seperately I need a loop. Instead of referring to each object seperately every time I want to redraw it, I want to loop through all instances of the object. Except I can't quite see how one goes about doing this. I need something like (pseudocode) Code: for (i = 0;i <= 10; i++) { var dot + i = new Dot; } and var b = numberOfDots; for (i = 0;i <= b; i++) { dot + i +.moveMe(); drawDot(dot + i + .posY, dot + i +.posX); } obviously this code does not work but it represents the essence of what i'm trying to do and can't get my head around, no matter the google searches I try. Hi there! I'm trying to retrieve the integer value in the string: #10 So I'm using the JS Split function Code: <script type="text/javascript"> var str="#10"; document.write(str.split("#")); </script> Is the code I'm using, but I keep getting a comma before my result.. in this case, my result is ",10" What should I do? Thanks! Kind Regards Matthew P.S. I know that it's an array, but is there still anyway for me to get rid of the comma? 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! Dear Users, I am trying to validate 4 radio groups (YES/NO) and get user to select at least one YES, doesnt matter which one. I am using a Spry Validation from Dreamweaver + the function listed below, but when I use this function the Spry Validation doesnt work, I think so I need to rebuild attached file (please change txt for js) function validate(f) { if(!f.RadioGroup1[0].checked && !f.RadioGroup2[0].checked) { alert('Please select at least one Yes'); return false; } return true; } I think so this is the place inside the Spry file to make a changes but I am ot quite sure how to make it // check isRequired if (this.isRequired && (nochecked == 0 || required != 0)) { this.addClassName(this.element, this.requiredClass); this.addClassName(this.additionalError, this.requiredClass); return false; } this.addClassName(this.element, this.validClass); this.addClassName(this.additionalError, this.validClass); return true; }; Hi, I am developing a html ordering system that does not use a database but sends the data via email. To differentiate between two orders I would like to generate and add an unique identifier to the email. One approach I have seen is using data object to generate an unique id: Code: function uniqid() { var newDate = new Date; return newDate.getTime(); } This is not guaranteed to be unique as two people can send their request at the exact same time. One question pops up, the data being generated, is this local or utc time? Also, the number being generated in this situation is quite big and not so easy to differentiate two orders for a human. Ideally I would like to generate a global sequence starting at 1 and incrementing by one for each user that clicks on the order button regardless of timing, timezone etc. Is this possible given the constraints given at the start of the post? Any suggestions are welcome. Hi, I'm using the following code to toggle checkbox checked and disabled attributes. Code: var f = false; function tick(group) { if (!f) { for (var i=0, len = group.length; i < len; i++) { group[i].disabled = true; group[i].checked = true; } } else { for (var i=0, len = group.length; i < len; i++) { group[i].disabled = false; group[i].checked = false; } } f == true? f=false:f=true; } The checkbox doing the js call uses onclick="tick(country)" and the checkboxes that I want to toggle all have the same id e.g. Code: <label><input type='checkbox' name='uk[]' id='country' value='England' />England</label><br /> <label><input type='checkbox' name='uk[]' id='country' value='Scotland' />Scotland</label><br /> This all works correctly but does not validate. I need to use unique id's for each name. The easiest way (as each checkbox html is generated by php) is to append the value to the id i.e. Code: <label><input type='checkbox' name='uk[]' id='countryEngland' value='England' />England</label><br /> <label><input type='checkbox' name='uk[]' id='countryScotland' value='Scotland' />Scotland</label><br /> How can I modify the javascript function factor this in i.e. toggle where id contains country? I downloaded "Unique Rate and Review" and have not been able to get the script working. Apperantly it's supposed to be easy so I feel quite dumb but can anyone please throw me a bone here?? This is my first experience with PHP and Javascript so please if you can help, speak in simple terms. My problem is that when anyone enters a review it says "You have already reviewed" and doesnt let anyone post. Take A look I have tried everything I can think of. Thank you. http://www.localkaraokeshows.com/cou...asallerate.php i have a function to dynamically create an image on the screen the problem is i need it to slide down the screen, and i am using the function to have the picture up in more than one place at more then one one time. is their anything i can build into the div tag containing the image that would let it scroll down on its own (or some other method of accomplishing this i haven't thought of) i am putting my function below Code: function newtree(){ x_axis=Math.floor(Math.random()*height); newdiv=document.createElement('div'); newdiv.setAttribute('style','position:absolute; left:'+x_axis+';top:0'); document.body.appendChild(newdiv); newimg=document.createElement('img'); newimg.src="Tree.png"; newimg.width="150"; newdiv.appendChild(newimg); } the 'height' and 'width' variable are already set to the available room in pixels Hi I've got about 40 check-boxes on my 1 form. These check-boxes all have names (obviously) but they are NOT all unique names. The number of UNIQUE names on my form is probably around 8 or 9 (the actual number is NOT important). Because some check-boxes use the same names as other. It's set up this way, please don't ask me to change it, I can't change it. What's the syntax/method for looping through all the names? I was thinking I should do maybe a "for" loop; Code: for (var i = 0; i < fieldName.length; i++) But I don't know how to hold a variable of the unique names to start with. Can someone help please? I have the following code as shown below: Code: <html> <script type="text/javascript"> var all = []; var a = ["1234", "Jim", "Lab1", "5455"]; var b = ["1235", "Jack", "Lab1", "5459"]; var c = ["1236", "Jane", "Lab1", "5455"]; var d = ["1237", "June", "Lab1", "5458"]; var e = ["1238", "Jill", "Lab2", "5461"]; var f = ["1239", "John", "Lab2", "5462"]; var g = ["1240", "Jacab", "Lab3", "5465"]; all.push(a); all.push(b); all.push(c); all.push(d); all.push(e); all.push(f); all.push(g); for(var i=0; i<all.length; i++){ document.write(all[i] + "<br>"); } </script> </html> How to I get the unique & in order of column 4 given that column 3 is given. Example: If the user provide the value 'Lab1' for column 3, the Javascript will return me the following? Code: "Lab1", "5455" "Lab1", "5458" "Lab1", "5459" I'm installing a Disqus commenting system on a news site. Javascript attaches a comment thread to the end of a story page, based on the story's url. Our issue is that many stories may have multiple urls, and we want a single comment thread on those stories. A single story may have a url like this: www.newspaper.com/ci_12345678 and this: www.newspaper.com/entertainment/ci_12345678 Disqus provides an alternative var disqus_identifier I'd like to define disqus_identifier to the final 8-digit story ID, read from the url. Here's the way the code looks: Code: <div id="disqus_thread"></div> <script type="text/javascript"> /** * var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread] */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://newspaper.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> I'm not sure how to define var disqus_identifier. Can anyone help me out? |