JavaScript - Should I Use A While Loop Or For Loop For This Script Involving Arrays?
Hi all
I'm well aware that I can't post assignments here and expect an answer, however, I have been staring at this code for so long. I feel I am close to the solution (to get the correct output to the browser) but I just cannot get it to count how many moves it takes. I don't want an answer, but a nudge in the right direction would be very grateful. As you can see from the code and the output, it will attempt to write to the browser how many moves, but only '0'. Code: function rollDie() { return Math.floor(Math.random() * 6) + 1; } /* *searches for a number in a number array. * *function takes two arguments * the number to search for * the number array to search *function returns the array index at which the number was found, or -1 if not found. */ function findIndexOf(number, numberArray) { var indexWhereFound = -1; for (var position = 0; position < numberArray.length; position = position + 1) { if (numberArray[position] == number) { indexWhereFound = position; } } return indexWhereFound; } //ARRAYS that represent the board -- you do not need to change these //array of special squares var specialSquaresArray = [1,7,25,32,39,46,65,68,71,77]; //array of corresponding squares the player ascends or descends to var connectedSquaresArray = [20,9,29,13,51,41,79,73,35,58]; //VARIABLES used -- you do not need to change these //the square the player is currently on var playersPosition; //play is initially at START playersPosition = 0; //what they score when they roll the die var playersScore; //the index of the player's position in the special squares array or -1 var indexOfNumber; //MAIN PROGRAM //TODO add code here for parts (iii), (iv)(b), (v), and (vi) // start of question(iii) playersScore = rollDie(); document.write(' Sco ' + playersScore); playersPosition = playersScore + playersPosition; document.write(', Squa ' + playersPosition); indexOfNumber = findIndexOf(playersPosition, specialSquaresArray); if (indexOfNumber != -1) { document.write(', Ladder to Squa ' + connectedSquaresArray[indexOfNumber]); playersPosition = connectedSquaresArray[indexOfNumber]; indexOfNumber = -1; } document.write('<BR>') // end of question(iii) // start of question(iv)(b) while(playersPosition<=80) { playersScore = rollDie() document.write(' Sco ' + playersScore) playersPosition = playersPosition + playersScore document.write(', Squa ' + playersPosition) indexOfNumber = findIndexOf(playersPosition, specialSquaresArray) if(indexOfNumber != -1) { document.write(', Ladder to Squa ' + connectedSquaresArray[indexOfNumber]); playersPosition = connectedSquaresArray[indexOfNumber]; } document.write('<BR>'); } var countMoves = 0; while(countMoves <= 0) { document.write('You took ' + countMoves + ' moves to get out'); countMoves = countMoves + 1 } /*for (var countMoves = 0; countMoves < playersPosition; countMoves = countMoves + 1) { countMoves = countMoves + playersPosition; document.write('You took ' + countMoves + ' moves to get out'); }*/ // end of question(iv)(b) // start of question (v) /*if (playersPosition >=80) { document.write('The player is out'); }*/ // end of question (v) </SCRIPT> </HEAD> <BODY> </BODY> </HTML> Many thanks. Similar TutorialsHi all, I have three arrays and what I would like to do is to check the present year to see in which array it could be found. If in the cycleA array then we would have document.write("Cycle A"); If in cycleB, then document.write("Cycle B"); etc. If it was just one array then an IF statement within a FOR loop would work, but I'm thinking there could be a more compact way of checking three different arrays instead of having three different FOR and IFs. Any help would be appreciated. George Code: <script> var cycleA = new Array("2011","2014","2017","2020","@023","2026","2029","2032","2035","2038","2041","2044","2047","2050","2053","2056","2059","2062","2065","2068","2071","2074","2077","2080","2083","2086","2089","2092","2095","2098"); var cycleB = new Array("2012","2015","2018","2021","2024","2027","2030","2033","2036","2039","2042","2045","2048","2051","2054","2057","2060","2063","2066","2069","2072","2075","2078","2081","2084","2087","2090","2093","2096","2099"); var cycleC = new Array("2013","2016","2019","2022","2025","2028","2031","2034","2037","2040","2043","2046","2049","2052","2055","2058","2061","2064","2067","2070","2073","2076","2079","2082","2085","2088","2091","2094","2097","2100"); var gpl = new Date(); var whatyear = gpl.getFullYear(); if(whatyear%2 == 0)document.write("Year II"); else document.write("Year I"); </script> I am stuck on these problems and cannot figure them out! Any help would be appreciated. Thank you! Code: public int sumkj(int k, int j){ // Complete the method using a for loop that will add the numbers from k to j, // where j is greater than k int total = 0; // TODO: ADD LOOP CODE HERE return total; } // whilesum10 public int whilesum10(){ // Complete the method using a while loop that will add the numbers // from 1 to 10 int total = 0; int i = 1; // TODO: ADD LOOP CODE HERE return total; } // whilesumkj public int whilesumkj(int k, int j){ // Complete the method using a while loop that will add the numbers // from k to j, where j is greater than k int total = 0; int i = k; // TODO: ADD LOOP CODE HERE return total; } public int dosum10(){ // Complete the method using a do-while loop (i.e. condition at end of loop) // that will add the numbers from 1 to 10 int total = 0; int i = 1; // TODO: ADD LOOP CODE HERE return total; } public int dosumkj(int k, int j){ // Complete the method using a do-while loop (i.e. condition at end of loop) // that will add the numbers from k to j, where j is greater than k int total = 0; int i = k; // TODO: ADD LOOP CODE HERE return total; } public String arrayprint(){ String msg = ""; String abc[] = new String[6]; abc[0] = "a"; abc[1] = "b"; abc[2] = "c"; abc[3] = "d"; abc[4] = "e"; abc[5] = "f"; // Create a loop that will output the values stored in the array abc // using a for loop and the array length // TODO: ADD LOOP CODE HERE return msg; } public String baseballOuts(){ String msg = ""; int totalOuts = 0; // Write a set of nested for-loops that willdetermine the number of // outs in a regulation baseball game. Assume: 9 innings per game, // 2 halves per inning, 3 outs per half inning. // You solution should include a loop (outer or nested) for each // of the assumptions. // TODO: ADD LOOP CODE HERE msg = "Total number of outs in a regulation baseball game is " + totalOuts + "."; return msg; } public String factorial (int n){ String msg = ""; int factnum = 1; // Use a loop to calculate the factorial of an input integer. // Note: If the input integer is too high an error may occur even if your // logic is correct. Why? At what value of input does the error occur? // How can you adjust the method so that either the error does not occur // or the method "fails gracefully?" Write your answers in the form of // a comment here. // TODO: ADD LOOP CODE HERE msg = n + "! = " + factnum; return msg; } } Ok, I'm nearly pulling my hair out with this one. I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together. What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array. What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created. Here is the test object: Code: test = [ { "name" : "Menu 1", "url" : "menu1.html", "submenu" : [ { "name" : "menu 1 subitem 1", "url" : "menu1subitem1.html" }, { "name" : "menu 1 subitem 2", "url" : "menu1subitem2.html" } ] }, { "name" : "Menu 2", "url" : "menu2.html", "submenu" : [ { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" }, { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" } ] }, { "name" : "Menu 3", "url" : "menu3.html", "submenu" : [ { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" }, { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" } ] } ]; Here is the recursive function: Code: function buildMenuHTML(menuData,level) { var ul; if (level == 1) { ul = "<ul id='menu'>"; } else { ul = "<ul class='level" + level + "'>"; } for (i = 0; i < menuData.length; i++) { menuItemData = menuData[i]; ul += "<li>"; ul += "<a href='" + menuItemData.url + "'>" + menuItemData.name + "</a>"; if (typeof menuItemData.submenu != 'undefined') { ul += buildMenuHTML(menuItemData.submenu,level + 1); } ul += "</li>"; } ul += "</ul>"; return ul; } Here is how the function is called initially: Code: buildMenuHTML(test,1); This is it's return value (with indentation added for readability): Code: <ul id='menu'> <li><a href='menu1.html'>Menu 1</a> <ul class='level2'> <li><a href='menu1subitem1.html'>menu 1 subitem 1</a></li> <li><a href='menu1subitem2.html'>menu 1 subitem 2</a></li> </ul> </li> </ul> 'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking, but any help would be appreciated. I have a userscript that goes through a table, once populated, and parses each item. If certain requirements are met, the item gets flagged. I want to add more to the script, but for some reason once the for loop has completed the script quits running. The alert("1"); will now show. This is like this in both Google Chrome and Firefox Code: var tbl = document.getElementsByTagName("table")[0]; var tlen = tbl.rows.length; for (i=1;i<=tlen;i++) { var cell = tbl.rows[i].cells[3]; var value = cell.firstChild.data; var nlen = value.length; if (nlen >= 10) cell.style.backgroundColor="#0AFE47"; if (nlen >= 15) cell.style.backgroundColor="#FF7575"; if (nlen <= 3) cell.style.backgroundColor="#CDD11B"; var nDigits = 0; for ( var t=0; t<nlen; t++) { chr = value.charAt(t); if (chr >= "0" && chr <= "9") nDigits++ } if (nDigits >=6) cell.style.backgroundColor="#FF7575"; var charcount = nlen - nDigits; if (charcount < 3) cell.style.backgroundColor="#CDD11B"; if (nDigits == nlen) cell.style.backgroundColor="#FF7575"; } alert("1"); I have simple script for my website, I want to redirecting a package tracking and get data from other website that have tracking service, So i try to make this simple field text, once it succesfully work, for 1-2 times, but it seems the script is not complete fungtionally, anyone can tell me where is the incomplete parts? because i think its endless loop of redirecting, and i got error message from chrome/opera/firefox browser this is the script: Code: <label for="basicSearchBox" style="font-size:8pt; font-weight:bold; color:#444444; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;">TRACK & TRACE</label> <form id="basicSearch" name="basicSearch" action="http://www.packagetrackr.com/track/parcelforce/" method="get" target="_blank"> <input name="searchTerms" id="basicSearchBox" type="text" value="" maxlength="200"> <input type="submit" value="Track!" style="background-color:#E5E3CB; border-color:#CAC594; border-style:solid; border-width:0pt 1px 1px 0pt; color:#71672D; font-size:.85em; margin:3px 2px; padding:0.0em; text-decoration:none;"/> </form> </div> Anyone can help? i really thanksful if someone can resolve my problems Just a little background on my problem.. I need to take a programing class to graduate college and I have never been good with code so I need some help. The teacher is asking for a script with a while-loop using rgb(..., ..., ...) that has to have the word Hello (10 times) in it, and the font color has to run from red (top) to green (bottom). The other question is write a script, using if-else to produce the following... A random number between 0.5 and less than 1. x is a decimal number between 0.5 and less than 1. We are using random number of the Math object This exercise requires you to put 2 statements in braces for the if-part and 2 statements in braces for the else-part. Any help would be greatly aprreciated.. Thanks Tom I have a slideshow on a test page at this link. I want to change it so that the slides loop rather than getting to the end and rewinding back to slide one. Can I alter the code (below) or would it be better to just find another code? Code: <script type="text/javascript"> $(document).ready(function() { var currentPosition = 0; var slideWidth = 1024; var slides = $('.slide'); var numberOfSlides = slides.length; var speed = 3000; slideShowInterval = setInterval(changePosition, speed); slides.wrapAll('<div id="slidesHolder"></div>') slides.css({ 'float' : 'left' }); $('#slidesHolder').css('width', slideWidth * numberOfSlides); function changePosition() { if(currentPosition == numberOfSlides - 1) { currentPosition = 0; } else { currentPosition++; } moveSlide(); } function moveSlide() { $('#slidesHolder') .animate({'marginLeft' : slideWidth*(-currentPosition)}); } });</script> Hello... Thanks for reading... I am getting an undefined error when i try to get a value from this array in the interior loop... Code: // This is the array I am trying to access AuditTable [0] = ["Visio Modifed date","Word Modified Date","User Status","User Comment","Last Audit","Audit Status","Audit Comment"] AuditTable [1] = ["11/23/2009 8:52:18 AM","missing","OK","user comment number 1","1/1/2009","ok","audit comment number 1"] AuditTable [2] = ["11/24/2009 12:21:19 AM","missing","Out of Date","Changes from 2008 not implemented","1/2/2009","Out of Date","needs update"] AuditTable [3] = ["11/22/2009 9:24:42 PM","missing","Incomplete","Document doesnt cover all possibilities","1/3/2009","Inadequate","needs update"] I have hard coded values and had success such as: Code: data = AuditTable[1][0] But when I put the vars associated with the loop in I get an undefined error - AuditTable[i] is undefined: Code: // produces error data = AuditTable[i][j] //Works but retrieves wrong data data = AuditTable[j][i] //Works but retrieves wrong data data = AuditTable[1][i] //Works but retrieves wrong data data = AuditTable[j][2] I must be trying to access the array incorrectly or something... I have defined all the vars, and tried many combinations, alerted the values of both vars so I can prove it is not a scope issue... Am I missing something obvious? Thanks much... Code: var reportArray=new Array(); var reportData, title, subTitle, data; for(i in parmarray)// loop thru AuditTable array and get values { title = '<div style="font-family:verdana; font-size:14px; font-weight:bold; margin:25px 0px 5px 30px">'; title += namearray[i][0]; title += '</div>'; reportArray.push(title);//Take compiled variable value and put it into array for(j=0; j < AuditTable[0].length; j++)// loop thru AuditTable array and get values { subTitle = AuditTable[0][j];//points to first row of AuditTable where the labels are data = AuditTable[1][0];//points to the current row where actual data is html = i + j +'<div style="font-family:verdana; font-size:12px; color:#696969; font-weight:bold; margin-left:30px;">'; html += subTitle; html += '</div><div style="font-family:verdana; font-size:12px; color:#a9a9a9; margin-left:30px; margin-bottom:10px">'; html += data; html += "</div>"; reportArray.push(html);// put results into array } } Ok javascript gurus, could someone help me out with a simple script? I have an array that I want to loop through and display the values of the array on the page as it loops (so I guess there should be a slight delay before the next one appears over it). I want to loop though until a button is clicked. Help? Hello, In the below script syntax, a simple table converts Celsius degrees into Fahrenheit, using the For loop and integrating it into a table. Code: <html> <head> <title>Celsius-Fahrenheit Converter</title> </head> <body> <table border=3> <tr><td>CELSIUS</td><td>FAHRENHEIT</td></tr> <script language="javascript"> for (celsius=0; celsius<=50; celsius=celsius+1) { document.write("<tr><td>"+celsius+"</td><td>"+((celsius*9/5)+32)+"</td></tr>"); } </script> </table> </body> </html> My questions are about the following script inside the <td> tags: <td>"+celsius+"</td> <td>"+((celsius*9/5)+32)+"</td> 1) why is the script inside the above <td> tags placed between " " ? 2) why is the script inside the above <td> tags placed between + + ? Thanks a lot for your explanation to an absolute Javascript beginner...! it wont loop, as long as you enter something in the name field it will submit. also how do i stop from submitting if all fields are not filled out? any help will be appreciated) ====== function checkForm(form) { var len = form.elements.length; var h=0; for (h=0; h<=len; h++){ if ((form.elements[h].value==null) || (form.elements[h].value=="")){ alert("Please enter "+document.myForm.elements[h].name); document.myForm.elements[h].focus(); return false; } return true; } } ===body-== <FORM NAME="myForm" METHOD="post" ACTION="http://ss1.prosofttraining.com/cgi-bin/process.pl"> Name:<BR> <INPUT TYPE="text" size="30" NAME="name"><br> Email address:<BR> <INPUT TYPE="text" size="30" NAME="email address" onBlur="emailTest(this);"><br> Phone number:<BR> <INPUT TYPE="text" size="30" NAME="phone number"><br> Fax number:<BR> <INPUT TYPE="text" size="30" NAME="fax number"><p> <INPUT TYPE="submit" VALUE="Submit Data" onClick="return checkForm(this.form);"> <INPUT TYPE="reset" VALUE="Reset Form"> </FORM> Hi, I am doing some studying and we was to create a small loop using either the for loop, while loop or do while loop. I chose to do the for loop because it was easier to understand, but I want to know how to do the same using the while loop. Here is the for loop I have, but I cant figure out how to change to while loop. Code: for (var i = 0; i < 5; ++i) { for (var j = i; j < 5; ++j) { document.write(j + ""); } document.write("<br />"); } output is equal to: 01234 1234 234 34 4 How do you make the same using a while loop? Hey guys i've just been following a few tutorials and learnt how to do a for loop and a while loop, what is the major difference between the two? they seem quite similar? I know while loops are laid out a hell of a lot easier in my opinion!
Hello, I recently purchased a JavaScript book, and I am confused by one of it's examples. I was wondering if anybody could answer my question. Here is the example: for (loopCounter = 1; loopCounter<= 3; loopCounter++) { //execute this code } Now, what I need help with is the variable part. The book goes on to say: ""To keep track of how many times you have looped through the code, you need a variable to keep count" My question is: Why does the variable have the value of one and not another number? I'm very very new to JS, I understand that the loopCounter has to be les than or equal to 3 for the code to execute, and also that it is incremented by one each loop, but the book is not clear on why the value of the variable has been set to 1. If anybody could answer this question I would be very grateful, I hate moving onto the next stage of a book if I do not completely understand the previous topics. Thank you in advance I have the following code which is almost completely working the way I need it to with the exception of the "downloadFile" value... Code: /*Regex list of download file extensions, pipe and backslash delimited. Looks for the period before the file type so it will work on download links with query parameters after it */ var downloadTypes = /\.pdf|\.doc|\.xls|\.zip|\.csv|\.ppt|\.rtf|\.pptx|\.docx|\.xlsx|\.wmv|\.mpg|\.exe|\.mp3|\.rar|\.wav/i; /*Regex list of on-site domains, pipe and backslash delimited. */ var onsiteDomains = /\mytestdomain1\.com|\mytestdomain2\.com|javascript|#/i; /*Used to unobtrusivly add events to objects*/ function unobtrusiveAddEvent (element,event,fn) { var old = (element[event]) ? element[event] : function () {}; element[event] = function () {fn(); old();}; } var links = document.links; if ( links ){ for(var i=0; i<links.length; i++) { if( links[i].href.match(downloadTypes) ){ unobtrusiveAddEvent( links[i], 'onclick' , function() { ntptEventTag('ev=download&eventPage=Download From: ' + escape( wa.currentDomain + wa.currentURL ) + '& downloadFile=' + escape( links[i] ) ); }); } if( !links[i].href.match(onsiteDomains) ){ unobtrusiveAddEvent( links[i], 'onclick' , function() { ntptEventTag('lk=1&ev=Exit Link'); }); } } } ...how do I grab the value of the href that was just clicked? links[i] is not working (it's just grabbing the href value of the last href in the loop). I am missing something simple for sure. Can anyone point out what I am missing? Thanks! I have a form that shows or hides divs based on what is chosen in a dropdown. There are 4 divs but only one is shown and the other 3 hidden based on dropdown selection. Inside each div are checkboxes with items for sale. I want to reset the checkboxes to unchecked and the line total values to 0 if the div is hidden. I've got the checkboxes to reset but I can't figure out how to set the line total values to 0 (There are 14 total so I'm trying to loop thru all of them and reset them.) This is what I have in the loop Code: for (var i = 0; i < form.elements.length; i++ ) { if (form.elements[i].type == 'checkbox') { form.elements[i].checked = false; } } // set line_totals to 0 for (var j = 0; j< form.elements.length; j++ ) { if (form.elements [j].name.substring(0,10) == 'line_total') { form.elements[j].value = ''; } } For those who read my other thread I finally scratched together the code to take a value from an XML file and add it to a select box as an option. Ofcourse it only does it once so I need to loop it. It's kinda complex though, here's a function line to add one option: addOption(document.people_form.People,name2,office2) And here's the code in the head: <script type="text/javascript"> //load xml file if (window.ActiveXObject){ var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; //Enforce download of XML file first. IE only. } else if (document.implementation && document.implementation.createDocument) var xmlDoc= document.implementation.createDocument("","doc",null); if (typeof xmlDoc!="undefined") xmlDoc.load("namedata.xml"); //Regular expression used to match any non-whitespace character var notWhitespace = /\S/ function getnames(){ //Cache "messages" element of xml file var nameobj=xmlDoc.getElementsByTagName("list")[0] //REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla for (i=0;i<nameobj.childNodes.length;i++){ if ((nameobj.childNodes[i].nodeType == 3)&& (!notWhitespace.test(nameobj.childNodes[i].nodeValue))) { // that is, if it's a whitespace text node nameobj.removeChild(msgobj.childNodes[i]) i-- } } } if (typeof xmlDoc!="undefined"){ if (window.ActiveXObject) //if IE, simply execute script (due to async prop). getnames() else //else if NS6, execute script when XML object has loaded xmlDoc.onload=getnames } var name2=xmlDoc.getElementsByTagName("name")[0].firstChild.nodeValue; var office2=xmlDoc.getElementsByTagName("office")[0].firstChild.nodeValue; var officePH2=xmlDoc.getElementsByTagName("officePH")[0].firstChild.nodeValue; var mobile2=xmlDoc.getElementsByTagName("mobile")[0].firstChild.nodeValue; var email2=xmlDoc.getElementsByTagName("email")[0].firstChild.nodeValue; </script> <script type="text/javascript"> function addOption(selectbox,text,value ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); } </script> Could anyone give me a pointer on how to loop this so that it loads one option after another from the XML file? Thanks. Hi All, im trying to to use a for loop to loop through a drop down list of users and if there is a match between the user logged in and the drop down list i want to enable two fields, if the user logged in isnt in the drop down list i want to disable the two fields, but im having trouble looping through, iv tried ".value" with no avail.. heres my Script Code: var RequestingUser = document.getElementById('JoinersLeaversContent_cmbRequestingUser').text; var Authorisers = document.getElementById('JoinersLeaversContent_ddlAuthoriseId'); for (var i = 0; i < Authorisers.length; i++) { if (RequestingUser.text == Authorisers.value) { document.getElementById('JoinersLeaversContent_txtAuthoriserSig').disabled = false; document.getElementById('JoinersLeaversContent_txtDateSignedOff').disabled = false; } else { document.getElementById('JoinersLeaversContent_txtAuthoriserSig').disabled = true; document.getElementById('JoinersLeaversContent_txtDateSignedOff').disabled = true; } } So just to be clear, if the user logged in appears in the drop down box i want to enable the two fields, if they dont appear i want to disable the two fields Please help. Thank you Hello all. I am faitly new at programming and have run into a little problem. I want to create a script that creates 2 random numbers, stored in 2 different variables and then compare them to eachother. there is two possible outcome of that comparison, either they are different or they are alike. If they are different i want to randomize a new set or numbers and make a other comparement, also to keep track on how many times i have created numbers. If they are alike i want to display the numbers and how many tries it took to get a matching pair. atm it looks like this <html> <body> <script> var x=(Math.floor(Math.random()*6)+1); var y=(Math.floor(Math.random()*6)+1); //creates two random int between 1 and 6 var throws = 1; //keep tabs on how many times we have thrown the dices if(x!=y) { x=(Math.floor(Math.random()*6)+1); y=(Math.floor(Math.random()*6)+1); throws=throws+1 }else{ document.write("you have rolled a pair. Dice 1 is: " +x +" and Dice 2 is: " +y +" and it took " +throws +" tries to get a pair."); } </script> </body> </html> How to get that into a loop? a really confused newbie scripter The following bit of javascript grabs a URL, checks whether it contains the string "abcjournals", and if so, replaces any subdomain before the "abcjournals" with "test.abcjournals". e.g. xyz.abcjournals becomes test.abcjournals. Code: <script type="text/javascript"> var loc = window.location.href; if (loc.match(/abcjournals/)) { loc = loc.replace(/[a-z]+\.abcjournals/, "test.abcjournals"); window.location.replace(loc); } /script> The above code works successfully, except that the page refreshes in an endless loop. If I add a "break;" or "exit;" after the window.location.replace line, there is no endless loop, but the URL string doesn't get replaced as expected. I've also tried using a "var i = 0;" adding "&& (i===0)" to the IF statement, and incrementing i within the IF statement; but again, the string doesn't get replaced as expected. Any suggestions much appreciated! |