weird javascript issues
-
Hi Guys, I'm not sure what I did, but I cannot figure out how to fix it. For some reason, my comparison operator isn't doing what it should be doing.
var Current = parseInt(document.getElementById("hiddenvalue").value);
var stopValue = Current + 5;
for (Current; Current < stopValue; Current++) {I have 5 elements in an array, so I have it setup to perform a function until it detects that the current value is no longer less than the stop value. What's really weird is, that it seems to be acting more like <= than just <. It still runs when current = 5. I don't think it's a problem with variable types because I can replace stopValue with 5 or even 4 but it will still run when the current value is equal to the stop value. when Current is equal to 5, shouldn't that stop because current < stopValue is no longer true? Another problem I am having is with changing the class after an image load:
var imageLoader = new Image();
images[image_counter].className = "image_loading";
images[image_counter].src = "/designElements/interfaceImages/loading26.gif";
imageLoader.onload = function() {
images[image_counter].className = "images";
images[image_counter].src = "/Gallery/Images/thumbs/" + imageObjects[Current].url;
}
imageLoader.src = "/Gallery/Images/thumbs/" + imageObjects[Current].url;does anyone see anything obvious that I'm missing? Thanks! the class does change initally to the image_loading class, but never seems to change back after the onload completes.
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
Hi Guys, I'm not sure what I did, but I cannot figure out how to fix it. For some reason, my comparison operator isn't doing what it should be doing.
var Current = parseInt(document.getElementById("hiddenvalue").value);
var stopValue = Current + 5;
for (Current; Current < stopValue; Current++) {I have 5 elements in an array, so I have it setup to perform a function until it detects that the current value is no longer less than the stop value. What's really weird is, that it seems to be acting more like <= than just <. It still runs when current = 5. I don't think it's a problem with variable types because I can replace stopValue with 5 or even 4 but it will still run when the current value is equal to the stop value. when Current is equal to 5, shouldn't that stop because current < stopValue is no longer true? Another problem I am having is with changing the class after an image load:
var imageLoader = new Image();
images[image_counter].className = "image_loading";
images[image_counter].src = "/designElements/interfaceImages/loading26.gif";
imageLoader.onload = function() {
images[image_counter].className = "images";
images[image_counter].src = "/Gallery/Images/thumbs/" + imageObjects[Current].url;
}
imageLoader.src = "/Gallery/Images/thumbs/" + imageObjects[Current].url;does anyone see anything obvious that I'm missing? Thanks! the class does change initally to the image_loading class, but never seems to change back after the onload completes.
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
compninja25 wrote:
for (Current; Current < stopValue; Current++) {
Do you need to initialise "Current"?
for (Current=0;Current < stopValue; Current++) {
-
compninja25 wrote:
for (Current; Current < stopValue; Current++) {
Do you need to initialise "Current"?
for (Current=0;Current < stopValue; Current++) {
Hi Marc, Thank's for the reply! I don't believe so. I wasn't thinking at the time but a few lines up in the code that I didn't copy I am initalizing 'Current' and setting it equal to whatever I have saved in my hidden variable. I have since changed it to a 'while' block instead:
while (Current < stopValue) {
It's just so weird though... I put an 'alert' line displaying both values in right after the while block and sure enough, I can watch it as it counts: (Current = 3; stopValue = 5, Current = 4; stopValue = 5, Current = 5; stopValue = 5) but rather than stopping like I thought it should, it continues through the while statement and causes the problem. (because I have a set amount of elements and when it tries to find that 5th element it comes back null. I understand the easiest fix I'm sure is to just subtract 1 from the stop value, but I would still like to discover why the function is seeing 5 < 5 as true?
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
Hi Marc, Thank's for the reply! I don't believe so. I wasn't thinking at the time but a few lines up in the code that I didn't copy I am initalizing 'Current' and setting it equal to whatever I have saved in my hidden variable. I have since changed it to a 'while' block instead:
while (Current < stopValue) {
It's just so weird though... I put an 'alert' line displaying both values in right after the while block and sure enough, I can watch it as it counts: (Current = 3; stopValue = 5, Current = 4; stopValue = 5, Current = 5; stopValue = 5) but rather than stopping like I thought it should, it continues through the while statement and causes the problem. (because I have a set amount of elements and when it tries to find that 5th element it comes back null. I understand the easiest fix I'm sure is to just subtract 1 from the stop value, but I would still like to discover why the function is seeing 5 < 5 as true?
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
have you tried:
for (i=Current; i < stopValue; i++) {
-
have you tried:
for (i=Current; i < stopValue; i++) {
Yea, that still does the same thing :/ it's just weird!
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
Yea, that still does the same thing :/ it's just weird!
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
You could try posting your code whole - I might be able to help more.
-
You could try posting your code whole - I might be able to help more.
<pre> function scroller_set(direction) { var imageObjects = new Array(); imageObjects = grabObjects(); var images = document.getElementsByName("selector"); var Current = parseInt(document.getElementById("scroller_current_value").value); var image_counter = 0; if ((direction == "next") && (Current < imageObjects.length)) { document.getElementById('backButton').style.visibility = 'visible'; var stopValue = Current + 5; while (Current < stopValue) { if (Current < imageObjects.length) { var imageLoader = new Image(); // images[image_counter].className = "loading"; images[image_counter].src = "/designElements/interfaceImages/loading26.gif"; imageLoader.onload = function() { // images[image_counter].className = "images"; images[image_counter].src = "/Gallery/Images/thumbs/" + imageObjects[Current].url; } imageLoader.src = "/Gallery/Images/thumbs/" + imageObjects[Curren
-
You could try posting your code whole - I might be able to help more.
I think I got it figured out. Although I'm setting the variable as an interger, I still need to use 'parseInt()' on all of my "current" variables that deal with any sort of logic gate. Is there a way you can specify a variable in javascript so that I don't need to use 'parseInt()' every time?
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
I think I got it figured out. Although I'm setting the variable as an interger, I still need to use 'parseInt()' on all of my "current" variables that deal with any sort of logic gate. Is there a way you can specify a variable in javascript so that I don't need to use 'parseInt()' every time?
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
I don't think so. Unless you remove any logic that make js think it's dealing with a string.
-
I don't think so. Unless you remove any logic that make js think it's dealing with a string.
Ah, turns out that wasn't it after all. If I remove the image.onload section, then it works, although it never changes to the desired image after it loads. I guess it's coming back to the 'onload' function after Current has hit 5 and that's where it's bombing out. I'll have to search for dynamic image.onload functions. So far, I've been basing my code from this [Update] it is definately something to do with the image.onload event. I was able to finally step through the code and it does work fine, but it appears that after the function completes, it then goes off and works on the rest of the page before coming back to the code in the image.onload event. Then, it tries to execute those lines of code but fails because the image_Counter is now 5. I thought that the image.onload would be setting a new function for each image box, but instead it looks like that is not the case. The overall goal is to have a "loading" gif display as the thumbnails are loading, but then display the image once it is properly loaded. I can get it to work just fine with a single static image, but not programatically for each of the thumbnails. Does anyone have any recommendations to help point me in the right direction?
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
modified on Monday, November 9, 2009 3:49 PM