By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

set size of image

P: n/a
Hi! I have a minor problem.
I want an file upload script to show a preview of the image that is about to
be uploaded, but I want it to resize the image to fit... say about 300x300,
no matter how big the image really is.
Here is the script:

<script type="text/javascript" language="javascript">

<!--

function dopreview()

{

if (uploadform.userfile.value != '')

document.getElementById("previewimage").src = 'file:///' +
uploadform.userfile.value.replace(/\\/, '/');

else

document.getElementById("previewimage").src = 'blind.gif';

}

-->

</script>

<form name="uploadform" method="post" type="multipart/form-data">
<input type="text" name="test" value="diverse tekst"><br>
<input name="userfile" type="file" onChange="dopreview();">

</form>

<img id="previewimage" src="tomt_bilde.jpg">

---------------------------------------------------------
Any suggestions will be apreciated!

Dag Eilertsen
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dag Eilertsen wrote:
Hi! I have a minor problem.
I want an file upload script to show a preview of the image that is about to
be uploaded, but I want it to resize the image to fit... say about 300x300,
no matter how big the image really is.
Here is the script:

<script type="text/javascript" language="javascript">

<!--

function dopreview()

{

if (uploadform.userfile.value != '')

document.getElementById("previewimage").src = 'file:///' +
uploadform.userfile.value.replace(/\\/, '/');

else

document.getElementById("previewimage").src = 'blind.gif';

}

-->

</script>

<form name="uploadform" method="post" type="multipart/form-data">
<input type="text" name="test" value="diverse tekst"><br>
<input name="userfile" type="file" onChange="dopreview();">

</form>

<img id="previewimage" src="tomt_bilde.jpg">


Validate your HTML.

<img name="previewimage" width="300" height="300" src="tomt_bilde.jpg"
alt="an image to preview" />

Life is so simple sometimes.......

document.images['previewimage'].src=.......;

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.