set size of image

D

Dag Eilertsen

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">
 
R

Randy Webb

Dag said:
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=.......;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top