title: Javascript Resize Image not working
body: <p>I have JS which resize the <code>width</code> and <code>height</code> of Image which is working fine if I used Alert before assigning the actual image src to the image object and if I omit the alertbox, it is not working. Please suggest me how to fix it. </p>
  
  <p>`       </p>
  
  <pre><code>&lt;html&gt;
          &lt;head&gt;
          &lt;script type="text/javascript" language="javascript"&gt;
          function resize_image_height_weight(id, hgt, wdth)
          {
              //alert(id);
              Obj=document.getElementById(id);
              myImage = new Image();
              myImage.src = Obj.src;
              var heights = myImage.height;
              var widths  = myImage.width;
          //  alert("Height=&gt;" + heights + " Width=&gt; " + widths);
  
              if(heights &gt; hgt || widths &gt; wdth)
              {
                  if(heights &gt; widths)
                  {
                      var temp = heights/hgt;
                      var new_width = widths / temp;
                      new_width = parseInt(new_width);
                      heights = hgt;
                      widths = new_width;
                  }
                  else
                  {
                      var temp = widths/wdth;
                      var new_height = heights / temp;
                      new_height = parseInt(new_height);
                      heights = new_height;
                      widths = wdth;
                  }
              }
              Obj.height = heights;
              Obj.width = widths;
  
          }
          &lt;/script&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;div&gt;
              &lt;center&gt;
              &lt;img src="http://www.google.co.in/intl/en_com/images/srpr/logo1w.png" id="i" alt="Google logo" height="150" width="150"&gt;
              &lt;script type="text/javascript"&gt;
                  document.images[document.images.length-1].onload = resize_image_height_weight("i",150,150);
              &lt;/script&gt;
              &lt;/center&gt;
              &lt;/div&gt;
          &lt;/body&gt;
          &lt;/html&gt;`
  </code></pre>