Function Loop Not Working - Finding The Alternative?
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.
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");
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...
I have a problem with FireFox. I have written a function to Add rows without submiting the form. This function works fine in IE, but not in FireFox. The function is :
function createRows(deviceId,deviceType,modelName,ipAddress,macAddress,imageURL) { oTable=document.getElementById("tab:tabForm: oTable");
var oRow1=oTable.insertRow(oTable.rows.length); var aRows=oTable.rows; var aCells=oRow1.cells; var oCell1_1=aRows(oRow1.rowIndex).insertCell(aCells.length); var oCell1_2=aRows(oRow1.rowIndex).insertCell(aCells.length); var oCell1_3=aRows(oRow1.rowIndex).insertCell(aCells.length); var oCell1_4=aRows(oRow1.rowIndex).insertCell(aCells.length); var oCell1_5=aRows(oRow1.rowIndex).insertCell(aCells.length); var oCell1_6=aRows(oRow1.rowIndex).insertCell(aCells.length);
I have these two functions used from Jquery i am looking for a alternative for them in javascript as i need to completely remove the jquery from the same code...
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.
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.
Now I want to apply the parent of tabContent a width, only if a condition is true. I do this, and works, but I don't consider this is a proper way: tabContent.css('width', '0') .css('opacity', '0') .filter(':eq(0)') .css('opacity', '1') .parent() .each(function() { if (/*condition is true*/) { $(this).width(aWidth + 'px'); } $(this).find('.one-tab') .addClass('active') .css('cursor', 'default'); }); Is there a better way instead of using each() which is actually made for loops? In this case there is only one element.
I would like to find out what script file a function belongs to. Better yet, I would like to know all of the functions that a javascript file declares.
I know that all javascript functions (and global variables) that are declared in a javascript file are added to the DOM. (This is easy to varify by adding a function to a js file and then adding that file to the page and then doing a for (all in window) document.write(all + '<br/>'); (or just looking in firebug) and seeing that your function is there.) What I want to know is what file that function belongs to.
Is there any way that I can make it so it hides all divs and then toggles the one I want WITHOUT having to write it out like this. is there a 'hide all' option?
I can't seem to figure out what I'm doing wrong with this no matter how many things I try. I've looked through Google for a related issue but found nothing specificThe script runs through a external .js file calling a list of music albums, then listing the song of the album chosen via ajax. The user can then edit of delete the songs. Everything works fine until I submit the edited information through a form. When I click the submit button I get a web developer error "updateSong is not a function"Here's the form which is loaded into the already existing page via ajax:
It's pretty simple stuff that just populates an empty div with an image link to bookmark the page when users have javascript enabled. Now when I call the function using <body onload="add_favorite();"> and cancel out the window.onload=add_favorite(); from the script it works just fine (it throws a line-1 syntax error up in IE that I can't figure out, but functionally everything still works in IE7 and FF2). When I try to do it the "unobtrusive" way I get nothing at all in either browser.
A little debugging revealed that the function is indeed being called and is running successfully, however the function is somehow unable to locate the element with ID of "bookmark" when it is fired with window.onload and as a result I get no bookmarking link. It's almost like window.onload is triggering itself too soon, before the div of "bookmark" is in the page, but how can that be?
The first time you click a radio button in IE8, no value is returned at all (tested with document.write of the 'check' value), with an error "'null' is null or not an object". The second (and rest of the times) you click any of the checkboxes the wrong value is returned, it returns the value of the currently checked button (which we checked a moment ago) rather than the one we have checked the second time. Does Internet Explorer have issues with this onchange function method? Or is something wrong with my code?
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.
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 ?
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.
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]
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.
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?
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]...
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.
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") {
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;
I'm working on a script(for giving points to a soccergame 0, 1 or 3 points) that give a value to a hidden field, i got a function but only works on 1 field.
I want that the function loops till all hidden fields are fill in.