473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

set size of image

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
1 1997
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Shaun McKinnon | last post by:
HI...Here's my problem...I have a popup window that loads when i want it to, but it's not sized properly. I've set the size, but it doesn't seem to work. I've been on 8 different websites to find...
7
by: YT | last post by:
Hello, I am this close | | to throwing myself out the window... I am trying to do a <UL><LI> series and i really really really want the disc size of the list to be nice and small. i've been...
9
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i...
7
by: Haines Brown | last post by:
I'm in the practice of specifying img width and height in my style definitions, although I usually use the actual size of the image. I'm reworking the style and it would be convenient to leave...
4
by: no-spam | last post by:
Hello, I have an HTML question that I'm not sure can be solved. I want to restrict the maximum size of an inline image. For example, I can force the image to be 200x200 if I do this: <img...
2
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error...
11
by: Parrot | last post by:
Is there any routine I can call to reduce the size of an image file after uploading a file from a client. I am looking to reduce file sizes programmatically using C# in my web page after uploading....
9
by: klausklausenator | last post by:
Hi all, I have a php-generated webpage with images. My problem is: the Internet Explorer cannot calculate the correct image size. Because of this the images are not cached. So everytime a user...
11
by: eholz1 | last post by:
Hello PHP group, I am using some php code to check the size of images, and then resize or determine new dimension for the image. GD seems quite slow. It takes about 5 seconds (plus or minus) to...
1
by: RYKLOU | last post by:
I am kinda new to php, but i do know what i am doing kinda, but i came across this error when i am trying to upload a file to my website. Fatal error: Allowed memory size of 8388608 bytes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.