Renidrag
06-09-2007, 08:52 PM
I have no problem uploading images to a file or into a database but I am having a heck of a time trying to view the image on the client side before uploading.
I have tried everything I am use to doing and I have searched for other answers, and copied a lot of other examples for changing the scr of an image to the file selected by the user but nothing is working.
I am testing with Firefox and IE 7 and here is some code below.
Any answers to help solve this would be greatly appreciated.
<SCRIPT LANGUAGE = "JavaScript">
<!--
var timerID = null;
var delay = 500;
function swap(filename){
clearTimeout(timerID);
filename = filename.replace(/\\/g,'/');
document.images["image1"].src = "file:///" + filename;
//document.images["image1"].src = filename;
alert("Image Src - " + document.images["image1"].src);
}
function StartTimer(){
if (document.form1.file1.value > ""){
//alert("Start Swap");
swap(document.form1.file1.value);
}else{
timerID = self.setTimeout('StartTimer()', delay);
}
}
//-->
</SCRIPT>
<form name="form1">
<p><input type="file" name="file1" size="20" onchange="StartTimer()"></p>
<img border="0" name="image1" id="image1" src="images/no_display_pic.jpg" width="200" height="150">
</form>
I have tried everything I am use to doing and I have searched for other answers, and copied a lot of other examples for changing the scr of an image to the file selected by the user but nothing is working.
I am testing with Firefox and IE 7 and here is some code below.
Any answers to help solve this would be greatly appreciated.
<SCRIPT LANGUAGE = "JavaScript">
<!--
var timerID = null;
var delay = 500;
function swap(filename){
clearTimeout(timerID);
filename = filename.replace(/\\/g,'/');
document.images["image1"].src = "file:///" + filename;
//document.images["image1"].src = filename;
alert("Image Src - " + document.images["image1"].src);
}
function StartTimer(){
if (document.form1.file1.value > ""){
//alert("Start Swap");
swap(document.form1.file1.value);
}else{
timerID = self.setTimeout('StartTimer()', delay);
}
}
//-->
</SCRIPT>
<form name="form1">
<p><input type="file" name="file1" size="20" onchange="StartTimer()"></p>
<img border="0" name="image1" id="image1" src="images/no_display_pic.jpg" width="200" height="150">
</form>