Passing variable between functions

Passing variable between functions

Hi Guys,

I'm trying to scale some images that are imported into the page. I'm setting up a dummy test image to get the orig. width, but the width is coming up undefined.  Strange since I'm reading in src for the image.
I tried setting up a closure function & even using window.variable, but nothing works.


Can someone please help me with this code.

  1.   function scaImage() {
  2.     $(function() {
  3.       var oiwd;
  4.       $('div[class^="searcher_stack-its_img"] img').each(function() {
  5.         var testi = new Image();
  6.         testi.src = $(this).attr("src");
  7.         $(testi).css({'visibility': 'hidden'});
  8.         $(testi).appendTo('body');
  9.         var isco = $(this).data("simgsc");
  10.         console.log('Orig Scale: ' + isco);
  11.         console.log('Image: ' + testi.src);
  12.         $(testi).on("load", function() {
  13.           oiwd = testi.width;
  14.           window.searcheriowd = oiwd;
  15.           console.log('Orig Wd: ' + oiwd);  // undefined
  16.         });
  17.         testi.remove();
  18.         oiwd = window.searcheriowd;
  19.         console.log('Orig Wd: ' + oiwd);
  20.         if (oiwd != 0 && testi.src != '') {
  21.           console.log('Src Check: ' + testi.src);
  22.           console.log('Scale Factor: ' + isco);
  23.           var scwd = Math.round(parseInt(oiwd) * parseInt(isco) / 100);
  24.           console.log('Scaled Wd: ' + scwd);
  25.           $(this).css({'width': scwd + 'px'});
  26.         }
  27.       });
  28.     });
  29.   }

Thanks,  Bill