Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. weird javascript issues

weird javascript issues

Scheduled Pinned Locked Moved Web Development
helpjavascriptcssdata-structurestutorial
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    compninja25
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • C compninja25

      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.

      M Offline
      M Offline
      Marc Firth
      wrote on last edited by
      #2

      compninja25 wrote:

      for (Current; Current < stopValue; Current++) {

      Do you need to initialise "Current"?

      for (Current=0;Current < stopValue; Current++) {

      Portfolio | Web Design, Web Hosting & IT Support

      C 1 Reply Last reply
      0
      • M Marc Firth

        compninja25 wrote:

        for (Current; Current < stopValue; Current++) {

        Do you need to initialise "Current"?

        for (Current=0;Current < stopValue; Current++) {

        Portfolio | Web Design, Web Hosting & IT Support

        C Offline
        C Offline
        compninja25
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • C compninja25

          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.

          M Offline
          M Offline
          Marc Firth
          wrote on last edited by
          #4

          have you tried:

          for (i=Current; i < stopValue; i++) {

          Portfolio | Web Design, Web Hosting & IT Support

          C 1 Reply Last reply
          0
          • M Marc Firth

            have you tried:

            for (i=Current; i < stopValue; i++) {

            Portfolio | Web Design, Web Hosting & IT Support

            C Offline
            C Offline
            compninja25
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • C compninja25

              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.

              M Offline
              M Offline
              Marc Firth
              wrote on last edited by
              #6

              You could try posting your code whole - I might be able to help more.

              Portfolio | Web Design, Web Hosting & IT Support

              C 2 Replies Last reply
              0
              • M Marc Firth

                You could try posting your code whole - I might be able to help more.

                Portfolio | Web Design, Web Hosting & IT Support

                C Offline
                C Offline
                compninja25
                wrote on last edited by
                #7

                <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

                1 Reply Last reply
                0
                • M Marc Firth

                  You could try posting your code whole - I might be able to help more.

                  Portfolio | Web Design, Web Hosting & IT Support

                  C Offline
                  C Offline
                  compninja25
                  wrote on last edited by
                  #8

                  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.

                  M 1 Reply Last reply
                  0
                  • C compninja25

                    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.

                    M Offline
                    M Offline
                    Marc Firth
                    wrote on last edited by
                    #9

                    I don't think so. Unless you remove any logic that make js think it's dealing with a string.

                    Portfolio | Web Design, Web Hosting & IT Support

                    C 1 Reply Last reply
                    0
                    • M Marc Firth

                      I don't think so. Unless you remove any logic that make js think it's dealing with a string.

                      Portfolio | Web Design, Web Hosting & IT Support

                      C Offline
                      C Offline
                      compninja25
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups