karayan
05-28-2003, 08:24 PM
I need to input a Windows path/filename and place it as an SRC in an <img> tag. The way I did it goes something like this: (the actual code I'm using is far more complex)
<form name="test">
<input type="file" name="testinp" width="60">
<input type="button" value="CLICK" onClick="trythis()">
</form>
<script>
function trythis() {
document.write("<img src = 'file:///" + document.test.testinp.value + "'>");
}
This writes into the document a line with <img src='file:\\\blabla'> where blabla is the path I just read from the file input in the form. This works well on IE even though the path the file input reads is full of backslashes (in the undying DOS path format). IE automatically converts the backslashes to slashes, etc. Even if folder names have blank spaces, IE replaces the blanks with %20. HOWEVER, if any item in the path has an apostrophe (=single quote mark) the script falls apart. (For example: C:\Joe's files\image.jpg)
Two questions then: 1) How do I handle the single quote marks?
2) Any other characters that might be in the path that I need to worry about?
Also, is there an easier and worry-free way to convert a path to an SRC value?
<grateful>Thanks.</grateful>
George
<form name="test">
<input type="file" name="testinp" width="60">
<input type="button" value="CLICK" onClick="trythis()">
</form>
<script>
function trythis() {
document.write("<img src = 'file:///" + document.test.testinp.value + "'>");
}
This writes into the document a line with <img src='file:\\\blabla'> where blabla is the path I just read from the file input in the form. This works well on IE even though the path the file input reads is full of backslashes (in the undying DOS path format). IE automatically converts the backslashes to slashes, etc. Even if folder names have blank spaces, IE replaces the blanks with %20. HOWEVER, if any item in the path has an apostrophe (=single quote mark) the script falls apart. (For example: C:\Joe's files\image.jpg)
Two questions then: 1) How do I handle the single quote marks?
2) Any other characters that might be in the path that I need to worry about?
Also, is there an easier and worry-free way to convert a path to an SRC value?
<grateful>Thanks.</grateful>
George