0

hi, i have this script work in FireFox, simetimes in I.E and never in Chrome, i need your help!!!Please...

thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
    
      var Width=200;
      // height to resize large images to
      var Height=130;
      // valid file types
      var fileTypes=["bmp","gif","png","jpg","jpeg"];
      // the id of the preview image tag
      var outImage="previewField";
      // what to display when the image is not valid
      var defaultPic="spacer.gif";
      /***** DO NOT EDIT BELOW *****/
      function preview(what){
      var source=what.value;
      var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
      for (var i=0; i<fileTypes.length; i++){
	  if (fileTypes[i]==ext){
	  break;
	  }
	  }
      globalPic=new Image();
      if (i<fileTypes.length){
	  
	  //Obtenemos los datos de la imagen de firefox
	  try{
	  globalPic.src=what.files[0].getAsDataURL();
	  }catch(err){
	  globalPic.src=source;
	  }
	  }else {
      globalPic.src=defaultPic;
      alert("Esta nao e uma imagem valida:nn"+fileTypes.join(", "));
      }
      setTimeout("applyChanges()",200);
      }
	  
      var globalPic;
      function applyChanges(){
      var field=document.getElementById(outImage);
      var x=parseInt(globalPic.width);
      var y=parseInt(globalPic.height);
      if (x>Width) {
      y*=Width/x;
      x=Width;
      }
      if (y>Height) {
      x*=Height/y;
      y=Height;
      }
      field.style.display=(x<1 || y<1)?"none":"";
      field.src=globalPic.src;
      field.width=x;
      field.height=y;
      }
      // End -->
      </script>

</head>

<body>
<tr>
<td rowspan="4" align="center"><img border="1px" width="180" height="130" alt="" id="previewField" align="middle" src="" /></td>
<td align="center"><input  name="arquivo" type="file" id="picField" style="" onChange="preview(this)" size="1"></td>
 </tr>
</body>
</html>
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by fatihpiristine
0

>> Line 21 - The variable "i" is only available in the for loop, and so on line 27 "i" is not declared.

>> Line 26 - GlobalPic not declared. Move var globalPic to line 1 from line 42.

>> Use alert() between the code to debug your code.

~G

0

hi, i m new in JS here, so if you can do that changes for mer i aprociate!!!

thanks...

0

I told you how to change the code so that it does work, and you can do that yourself. Use alert()'s between to see where the code fails. Try some things yourself, and if you can't figure it out, post your new code and I'il guide you further.

~G

-1

etTimeout("applyChanges",200); // remove brackets

Votes + Comments
No code tags, poor advice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.