JavaScript setTimeout Issue

So, I realized how stupid I was today when I was trying to build a slideshow with JavaScript. Well, I'm obviously going to use the setTimeout or setInterval timing functions.

Well, my JS code was quite extensive due to it being integrated with other functionality. Here is an example of the code:

// Show the thumbnails.
for (var t = 0; t < preLoad.length; t++) {
   if (document.getElementById("thumb_" + t)) {
      document.getElementById("thumb_" + t).style.border = "2px solid black";
      }
   }
document.getElementById("thumb_" + j).style.border = "2px solid blue";
   
t = setTimeout("runSlideShow('forward',false)", slideShowSpeed);

If you can see my problem, its because I used the "var t" in the loop and then used it as the object for the setTimeout. Well, there is actually a "var t;" declaration outside of this function that makes the t variable global. So, after trying to access it after the loop, it caused all sorts of problems, like multiple timeouts running at the same time on one slideshow. Whew it was confusing.

Anyway, once I changed that "var t" in the loop to say "var k", it all worked fine.

IE 6 and the Dreaded "Operation Aborted" Dialog

As I was developing some pretty complex stuff with IE, it kept spitting at me with a dialog box that said "Operation Aborted." After looking through the code, which was mostly manipulating the DOM, and asking my good friend Google, I found that the manipulation of an element that is not fully created, causes real problems with IE. In other words, I was trying to manipulate a <div> tag before it finished creating the end tag.

This is pretty common with IE. So, beware, another IE issue (albeit and old one) to deal with.

Securing HTML Forms

I'll admit that I sometimes use hidden form fields in my web applications. I cringe every time I do, but I do it anyway. They're convenient and make it easy to track some elements in a web application.

The problem with hidden form fields is that users can manipulate them. This is done by simply saving the web page to disk, modifying the code, then opening the page on disk in a web browser and submitting the form. This is dangerous and can cause severe problems. Hence, securing forms is essential. This is how I do it:

[More]

Contact Chris SchofieldBlogCFC was created by Raymond Camden. This blog is running version 5.9.001.