Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkendSoul

Preview local images

Recommended Posts

Currently im using the following script in an attemp to preview local images before submitting them but it doesnt change...

[code]
        <tr><td class="text">Image:</td>
            <td><img id="icon" class="world">
                <input type="hidden" name="MAX_FILE_SIZE" value="5000" /><input type="file" name="char_pic" size="15" class="char_pic" onclick="icon.src = 'file:///' + this.value" /></td></tr>
[/code]

does anyone know why? the file exists...

Share this post


Link to post
Share on other sites
hey, cool. it works.

problem is the onClick. Clicking the button opens the browse window while the javascript attempts to load an unselected image to the image source. After you select a picture, click it again and the image pops right up.

maybe onclick isn't the right way to do this? maybe a <body onFocus> or something?

Share this post


Link to post
Share on other sites
hrm body focus doesnt work out for me just due to the theme script which goes basicly like...

<html>
<body>
{MAIN}
</body>
</html>

where {MAIN} is it loads all the info into. so yeah... accessing body easily doesnt work very well. ;)

i changed it to onChange... doesnt work

Share this post


Link to post
Share on other sites
What about a setInterval that checks this.value for a value every three or five seconds. Onclick starts the setInterval, and the function called by setInterval will assign the image source and unset the interval upon finding a value?

Share this post


Link to post
Share on other sites
[code=php:0]var my_var = setInterval("somefunction",5000);[/code]

That would fire the function every five seconds.

http://developer.mozilla.org/en/docs/DOM:window.setInterval
http://developer.mozilla.org/en/docs/DOM:window.clearInterval

[b]PS>[/b] it is case sensitive and firefox is very very case sensitive. Also, the quotes aren't listed in the manuel, however, I found that firefox wouldn't work without quoting the function to call.

Share this post


Link to post
Share on other sites
You should probably be using the onchange handler, not onclick.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.