Archive

Archive for November, 2006

Firing an onchange event from a HTMLSelectElement

November 17, 2006 Leave a comment
Something I just solved, which alot of people seemed to be stuggling with, is the ability to fire the onchange method of a select
box programatically from .NET (in this case VB.NET)
 
Basically the problem is, if you have a drop down list, stored in a HTMLSelectElement, and you set the selectedIndex propery, the onchange event doesn’t automatically get called. – the same happens in Javascript – but you can’t call onchange() like in Javascript, since it’s a property, not a method.
 
Solution
 
hse.FireEvent("onchange", hse.onchange)
 
where hse is the HTMLSelectelement
 
 
Categories: Uncategorized

Javascript redirect after images have loaded

November 10, 2006 Leave a comment

This is a handy piece of javascript that can be used to execute a redirect only after all images have loaded on a page, up to a maximum of 10 seconds. I put in this maximum threshold, to account for the possibility of a bad link on the page, or a user with images turned off on their browser.

waitForImages();
var imageLoadTimeout = 10; // max 10 seconds;
var timeWaited = 0;
function waitForImages()

 var AllLoaded=true;
 if (timeWaited>imageLoadTimeout)
 {
  // redirect after 10 seconds, regardless of whether images are loaded.
  ImagesLoaded();
  return;
 } 
 for(i=0;i<document.images.length;i++)
 {
  var image = document.images[i];   
  if (!image.complete && image.name != "brokenImage" )
  {
  
   AllLoaded=false;
   break;
  }
 }  
 if (AllLoaded)
 {
  ImagesLoaded();
 }
 else
 {
  timeWaited += 0.5;
  setTimeout(‘waitForImages()’,500);
 }
}

function ImagesLoaded()
{
 RedirectPage();
}

Categories: Uncategorized