Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>problem with an ImagePreview js

problem with an ImagePreview js

tcadieux
11-23-2005, 08:43 PM
I use the below code to display an image to my client when they have browsed to it. The image folder is in another location but always the same. My problem is that when i browse to the image, this code works fine, however, if i just paste the filename in, it does not display becuase the path is always incorrect.

I'm sure it's just a logic problem but today is one of those days and i just don't see the solution.

TIA

Function DisplayImage(ImageName,ElementValue){
document.images[ImageName].src= http://codingforums.com/archive/index.php/ElementValue;
}
<img src=http://codingforums.com/archive/index.php/"../Images/6_1/Blank_image.jpg" name="preview_h" width="103" height="112" id="preview_h">
<input name="headline_photo" type="File" id="headline_photo" size="17" onChange="DisplayImage('preview_h',this.value)">

pccode
11-24-2005, 06:34 AM
I'm not sure if you're talking about inserting an image locally from the client computer, but I rewrote the code so that you could test it locally.


<html>
<head>
<script>

function DisplayImage(ImageID,ElementValue) {
var temp = ElementValue.replace(/\\/g,"/");
temp = "file:///" + temp;
document.getElementById(ImageID).setAttribute('src',temp);
}

</script>
</head>

<body>
<img src=http://codingforums.com/archive/index.php/"reply.gif" name="preview_h" width="103" height="112" id="preview_h">
<form onreset="window.location.reload()">
<input name="headline_photo" type="File" id="headline_photo" size="17" onChange="DisplayImage('preview_h',this.value)">
<br><br>
<input type="reset" value="reset">
</form>
</body>
</html>


With a local file you need to add "file:///" to the beginning of the url and change all of the backslashes to forslashes. In FF it does not automatically activate the onchange event when you paste text into an input box. You need to hit enter to activate the event handler. I have no idea about IE since I haven't tested it with this code. One other note, if you do decide to paste a local file url into the input box, don't worry about reformatting it since the code above will do it for you.

tcadieux
11-28-2005, 07:36 PM
Thank you, this does work in certain instances.

However, i think the easiest thing for me to do would be to strip all information save for the file name and then display the file at a hardcoded location.


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Anyone knows to clear the contents of the window !!! in javascript
Automatically generates color tags(<color="red">,</color>)
document.getElementByID() Issues
Adding onclick stuff to an INPUT through javascript
Netscape Problems :-(
Can function RETURN a value?
do I need a random script script or not?

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics