Change Image to File Input Value
I simply want to change the current image to the value in the file input box.
Here's what I have
Code:
<form name='form1' method='post' enctype='multipart/form-data'>

<input type='file' name='image' onChange='document.image1.src="document.form1.image.value">
</form>
When I select an Image, the image changes but is not found.
I believe it's because of the backslashes in the path from the file field.
I hardcoded a path to an image with forward slashes rather than backslashes
an it worked fine. But the file field returns backslashes.
Any ideas?
Thanks
lee20
Re: Change Image to File Input Value
Quote:
Originally posted by lee20
I simply want to change the current image to the value in the file input box.
Here's what I have
Code:
<form name='form1' method='post' enctype='multipart/form-data'>

<input type='file' name='image' onChange='document.image1.src="document.form1.image.value">
</form>
When I select an Image, the image changes but is not found.
I believe it's because of the backslashes in the path from the file field.
I hardcoded a path to an image with forward slashes rather than backslashes
an it worked fine. But the file field returns backslashes.
Any ideas?
Thanks
lee20
im not sure about java script, but you might try this code snippet:
Code:
function replaceChar(base, rid, add) {
for (var p = base.indexOf(rid); p > -1; p = base.indexOf(rid))
base = base.substring(0, p) + add + base.substring(p + rid.length);
return base;
}
and do a replaceChar(filepath, '\', '/') to change the \ to / in the path....