Nested For Loop Not Working
Oct 1, 2011
this is code for a conway's game of life. the nested loop on stepGen() doesnt work and i cant figure out what it is. no syntax errors, or anything. i put alert statements to see whats happening. i can provide the rest of the code if necessary.[code]
View 2 Replies
ADVERTISEMENT
Jul 23, 2005
i have a nested loop in Javascript and i have a break statement in inner loop. As break statement takes control come out of inner loop. I want to come out of both loops if break statement reaches in inner loop. is there any way to do that ??
View 1 Replies
View Related
May 30, 2004
I've encountered a problem with setTimeout() which I haven't really been able to solve. The problem is that setTimeout works like this:
setTimeout(code, delay) {
// In delay milliseconds, evaluate code
}
Here's the setTimeout I'm trying to use:
setTimeout("result_area.innerHTML += result_string;", delay);
This is nested in a for loop, where result_string changes every time. This raises a problem because what it tries to do is this:
// In delay milliseconds, evaluate "result_area.innerHTML += result_string;"
What I want it to do is the following:
// In delay milliseconds, add whatever result_string is right now to result_area.innerHTML
Unfortunately I can't figure out a way to do this. Does anyone have any answers for me?
View 2 Replies
View Related
Jan 20, 2011
What I have is a dynamically created group of unordered lists. My jQuery code allows the user to "add" forms that essentially create a new unordered list per form. The first list item is displayed in a heading 2 tag strictly for the style formatting the h2 tag gives.
The user enters data in the forms which are then passed via url.data method to my action page. This is where my code loops(nested loop) through the lists, inserts the appropriate items in either the heading 2 tag or the rest of the list item tags. Then this(these) lists are saved in a temporary file and then called and displayed back by way of an include. The problem is I want these lists to be sorted alphabetically. I have a function that I am close to getting it working, but the problem I think is the fact that I have the special "first" list item within a heading tag.
Here is the function:
var items = [];
$('li').each(function() {
items.push($(this).text());
[code].....
View 2 Replies
View Related
Nov 21, 2009
I really can't figure out why it's not working in IE. The only problem I can think of would be using nested loops. Here's the part of the code that isn't working. It's not generating an error, it's just not returning anything. I know you guys hate when I post entire code, so I trimmed it down as much as I can. It's referring to an already stated xml document with xmlDoc. And it's goal is to return a table of rows that meet certain criteria. If you can see any syntax errors that explorer would not like, that's really what I'm asking for.
[Code]...
View 6 Replies
View Related
Sep 16, 2009
full sample script which demonstrates the problem, inner tabs company/department come up as list instead of tabs.I have already tried what People have suggested that inner tabs should also be tabified via jquery but it doesn't work all the examples I have seen e.g.URL... use topmost div for jquery tabs call.[code]
View 6 Replies
View Related
Aug 1, 2011
I have some set of div elements as follows,
<div class="parentCell_1">
<div class="children"></div>
<div class="children"></div>
[code]....
View 4 Replies
View Related
Jul 21, 2010
I have while loop, where something is defined via ID, I called it pin_click.
So of course there are a few entries.
And I have the following Code:
Somehow, this Code only works for the first element, I get out of the while loop. The other elements of the while loop ( which have the same Button ) are just doing nothing, even no action in Firebug.
View 6 Replies
View Related
Oct 6, 2009
I have a form on my page that gets checked and verified with a bit of AJAX and then gets sent off if all is good, but I also created a quick little loop to verify that all the fields are still full and completed before sending the info off to the server officially .here is my test page for the loop that i have created.
PHP Code:
<html>
<head>
<script type="text/javascript">
[code]...
Now the loop works great if you test it by clicking on the button once but if you fill in a missing field and click the button ok then it doesnt work again ... how can i get it to work on every click ?
View 3 Replies
View Related
May 5, 2010
I'm trying my first bit of jQuery code but am familiar with Java programming. I'm trying to create a function that loads a div with an image in it, which will fade in and then after 4 seconds move onto the next image. I want it to create an infinite loop but it doesn't work.
<script type="text/javascript">
$(document).ready(function ()
{
[code]...
View 4 Replies
View Related
Oct 11, 2011
i have this code
<script type="text/javascript">
$(document).ready(function() {
for ($i=0; $i<4; $i++) {
var num = $('.clonedInput').length;
[Code].....
the input id is changed correctly, but valores no. Why ?? Valores is always id="valores1", and must be id="valores1", id="valores2", and so on.
View 2 Replies
View Related
Jul 17, 2009
Why wont my for loop work it wont alert the var images1....
<script type="text/javascript">
for(i=1;i<6;i++){
images[i] = "no"+i+".jpg";
[code]...
View 2 Replies
View Related
Dec 9, 2004
I have a javascript that is supposed to read a text file (a log from a php script) and it should be shown in a html page. Even more, it should read that txt file again every 10 seconds and update the result every time on the page.
I use xmlhttp for this, after a suggestion from someone on this forum. My script is working well, but only the first time the page is loaded. From then on it becomes unrelieable and I dont know why.
This is the first part: loading a function in the body tag, and a browser version check, I dont think there is any problem in this.
Code:
<body onLoad="showbuffer();">
<script language="JavaScript">
<!--
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
//-->
</script>
This is the second part, a self made looping function that looks up buffer.txt , and writes it on the page.
Code:
<script language="JavaScript">
<!--
function showbuffer() {
xmlhttp.open("GET", "buffer.txt",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
buffertext=xmlhttp.responseText;
document.body.innerHTML= buffertext;
}
}
xmlhttp.send(null)
return false;
setTimeout('showbuffer()', 10000);
}
//-->
</script>
And this works, if I load my page then it shows exactly the content of buffer.txt . And if a bit later some data is added to the txt file, then it doesnt show up in the xmlhttp page , its still the same content as from the beginning so it didnt update. But there is something really weird about it, if I open up a second browser window and typ in the complete url of the buffer.txt file, and visit that page and look at the new data... then within 10 seconds the new part is added to the xmlhttp page. So the javascript function doesnt work, unless I refresh the page it is supposed to read. I've tried to mimic that, with a php script in crontab that would read buffer.txt through file(); or fopen(); every minute , but that didnt seem to work.
I dont think there is anything wrong with all the xmlhttp part of it, but rather with the way I try to integrate it into a loop. But this setup with setTimeout is the only way I know to make a function repeat itself with a few seconds delay after every step.
So, could anyone please point out how this could be solved ? Maybe another way to loop the xmlhttp part perhaps?
View 1 Replies
View Related
Jun 8, 2009
I have a pretty simple function set up to pull XML data into my page, but there's a couple things wrong with it. I'm REALLY new to J Script and really trying my best to learn, but for some reason I'm not yet adept at googling the right results :rolleyes:At the very bottom you can see the data from the first XML entry, so it seems the function itself is working fine, but it's not looping coorectly to access all the data.Also, I want to pull it into the "shows" div of the page, but can't figure out how to put it there (seriously, I am very new with JS). The code below is not working, but the live site has it added to the body, which does show the one entry.Here's the XML function, the XML data and the HTML markup:
Shows function -
function loaddates()
{
var xmlData = document.getElementById("tourdates");
var newDates = xmlData.getElementsByTagName("dates");
[code]...
View 4 Replies
View Related
Apr 3, 2010
I have a simple HTML page with one DIV element with the id "rotator". Inside that, JavaScript is supposed to create boxes that react to mouseovers.
The weird thing is: The whole script works, but ONLY on the LAST box I create, no matter what I do. I can manually add the mouseover code to any one of these boxes, but it will only take on the last one. I can have JavaScript tell me the mouseover status of each box, and they all tell me they have code assigned correctly - but again only the last one works...
Here's the relevant code (yes, highly abbreviated, but it's the part that fails on me):
var maxBoxes = 10;
function initSite() {
var rotator = document.getElementById("rotator");
rotator.innerHTML = "";
[Code]....
initSite is called in the body onload. All kinds of other animation parts are implemented that work fine, just this mouseover won't work. I have tried re-writing it in multiple different ways, including "xyz.onmouseover = myMouseCode" and then defining the function separately later - still no dice.
So, the code creates 10 boxes (0-9) and 10 boxes that are on top of them to create a form of shadow effect depending on the position of the original boxes. Since the "myDark" boxes are on top of the "myBox" boxes, I apply the onmouseover onto the "myDark" boxes, but it only works on "myDark9" and no other box. They are all created the same way, the mouseover assigned the same way...
View 8 Replies
View Related
Jun 4, 2010
Here's the code:
for (var i = 1; i < 5; i++)
var pl = eval("player" + i)
var namepl = eval("document.charInput.name" + i + ".value");
[code]....
In the case of the 2nd-4th player, it changes to name2.value, etc.Based on these three inputs, I need to iterate through all four players and make the player object for each of them, as I've done above.
View 5 Replies
View Related
Jun 6, 2011
I'm not so good at Javascript, but I tried to write some code to obtain some form values and write those to a query string to use in AJAX.It seems to be working partially, but I don't understand what is going wrong. What happens is that in the for loop the 'document .form_name.form_field_names_array[i].value' part doesn't seem to return a value. It is worse even: the script completely stops executing at that part. When I remove that part from the line in the for loop, it doesn't stop executing, so I guess that's where the problem is?
function doAjaxForm(url, target_element_id, img_url, form_name, form_field_names)
{
// Create the GET query string from the form_fields[code]...
// Rest of the code (the AJAX) is working.
View 3 Replies
View Related
Jan 18, 2010
I cant get collision detection to work. I tried but it always caused an infinite loop.
Heres the code.
<html><!-- main file.--><head>
<title>lightning generator</title>
</head><body>
<canvas id='world' width='500' height='500' style='border: 1px solid black; padding:0;'>
</canvas><script type="text/javascript" src='world.js'></script>
[Code] .....
In the end of world.bolt.cpath,there should be a way to use the local varis X and Y, and world.ground.js's world.ground.level[] to detect it. sorry for the gigantic length.
View 1 Replies
View Related
May 6, 2010
Does anyone know why this isn't working? The toggle function works perfectly fine with PHP loops, but when I insert the table td tr tags, it does not hide the loop when the page first loads...It just shows the results in the div which it shouldn't be doing.
Here's what my code looks like...
JS
Code:
<script type="text/javascript">
function toggle(element) {
if (document.getElementById(element).style.display == "none") {
[Code]....
View 3 Replies
View Related
Apr 8, 2011
Having a tough time integrating the 2. Trying to create 2 loops, the inner one I had working as below, until I tried to add the outer loop which iterates through the tables
<script type="text/javascript">
// <![CDATA[
var i=0;
[code]....
View 7 Replies
View Related
Aug 28, 2010
i am trying to pass text from one select box to another select box. The logic is if 10 are added, no more passing must happen. Also if an item is already added, it mustn't be added again.I am using the for loop to check the existence of an item but it is not working: what am i doing wrong?
Code:
function PassSelectValues(){
//pass values from select boxes to select boxes
var counter;[code]....
why isn't counter incrementing at all? The alert message box does appear saying item exists but the item gets added anyway.
View 1 Replies
View Related
Oct 11, 2009
I'm building a t-shirt shop whose interface includes a gallery of designs in an IFrame. When the user clicks on a design, a dedicated page is loaded into the IFrame which shows all the available products associated with the design the user clicked.
I've put each design's image and associated page as the first and second elements of a nested array, and am using a for loop to then load all the images into the page that's shown in the IFrame when the web-site loads. It's looking beautiful, but here's the rub I've been stuck on for two days now with no solution in sight...
The array, "designImages", has 37 elements (ie. designImages[0]... designImages[36]). When I click on a design image on the page, any design image, the browser (all browsers, so I can't blame Microsoft for this one :rolleyes: ), loads the page for design #36. I've tried all sorts of things, but still cannot tell if the issue is because the dynamically generated divs are being reassigned the value [36] after the for loop's executed, or if the div id's are okay but somehow the code is rooting for [36], the last element of the array anyway.
[Code]...
View 2 Replies
View Related
Jan 22, 2011
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:
test = [
{
"name" : "Menu 1",
"url" : "menu1.html",
"submenu" : [
[Code].....
'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking.
View 2 Replies
View Related
Aug 4, 2011
I'm looking to send a loop variable (i) to a function inside the loop, but I can't seem to get it to use the value I want, it keeps making it a reference of i and therefore the function is always called using the last value of i rather than the one it was set with.
So if i have 5 Tabs then Tab 1, when clicked, should call DefaultTabClick(0) and so on rather than always using 4 for any of the tabs.
View 2 Replies
View Related
Sep 20, 2011
When I open a page in IE (any version), it throws a script error pointing at this line:
for (item in fieldList) {
$('[name=' + fieldList[item] + ']').addClass('required');
};
Where fieldList is a list of form fieldnames that I want to apply this class to. But the error points right at the "for" on the first line. Is something up with IE where it doesn't support that kind of loop?? Of course it works fine in FF and Chrome. And Safari. And Opera.
There's probably a better way to do it in jQuery, but I'm not familiar enough with loops in jQuery yet.
View 2 Replies
View Related
Jul 29, 2011
I have the code below, how could it be modified to loop over and over and reload the xml file each time. Flow would be: load xml, run thruogh code to display each xml node one at a time, when reach last node, start all over, reloading xml file,
[Code]...
View 2 Replies
View Related