<html>
<body>
<div align="center">
<form name="imageTest">
<input type="file" name="myImage" size="30"/>
<input type="button" value="Preview!" onClick="previewImage(document.imageTest.myImage,'replaceMe')"/><br>
<img src="MyImg.jpg" name="replaceMe" id="replaceMe"/>
</form>
</div>
</body>
</html>
<script language="javascript">
var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
function previewImage(pathField, previewName)
{
var path = pathField.value;
if (path.search(imgRe) != -1)
{
//document[previewName].src = document.imageTest.myImage.value;
document.getElementById("replaceMe").src = document.imageTest.myImage.value;
}
else
{
alert("JPG, PNG, and GIFs only!");
}
}
</script>
The above code Not work in Crome and IE.
Can you please tell me y?