473,568 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preview image before upload.


I have a form to allow the user upload images.
The user browse for an image in their computer and click open, th
image to be upload is preview on the img tag.
The script works fine with IE, but does not work with mozilla Netscap
bowsers.
Does anyone knows what could be the problem?
Does the ONchange function works in Netscape?
Or anyone knows a tag that can preview the image file before uploadin
it.

<script language="JavaS cript" type="text/JavaScript">
function preview(thisImg ,thisObj)
{

var filename = "";
var nothing = "";
filename = "file:\/\/"+thisObj.value ;

var fileExtension
filename.substr ing(filename.la stIndexOf(".")+ 1);
if (fileExtension == "jpg" || fileExtension == "jpeg" |
fileExtension == "gif")
{ thisImg.src="fi le:\/\/"+thisObj.value ; }

else
{ alert ("Only jpg, jpeg and gif file
are allowed."); }

}
</script>

<form name="form2" method="post" enctype="multip art/form-data">

<img src="images/default.gif" name="myimga" width=100 height=8
border=0>

<INPUT NAME="upfile" TYPE="file" SIZE="80
ONchange="previ ew(myimga,upfil e);">

<INPUT NAME="upload" TYPE="submit" VALUE="Upload">

</form
-
miart

Jul 20 '05 #1
4 32227
On Thu, 26 Feb 2004 13:48:08 -0600, miarte
<mi***********@ mail.forum4desi gners.com> wrote:
I have a form to allow the user upload images.
The user browse for an image in their computer and click open, the
image to be upload is preview on the img tag.
The script works fine with IE, but does not work with mozilla Netscape
bowsers.
Does anyone knows what could be the problem?
Does the ONchange function works in Netscape?
Strange capitalisation, there.
Or anyone knows a tag that can preview the image file before uploading
it.
The first problem is that you are referring to elements as though their
names are global identifiers. They are not - it is an IE thing (though
some other browsers might imitate it). Use the appropriate collections
(addressed later).

Another problem is that the onchange event won't fire properly in all
browsers. In IE and Opera, it works fine. In Netscape, you have to lose
focus on the control before it updates the image, and that seemed somewhat
tempermental. In Mozilla, nothing happens. The best approach, in my
estimation, would be to use a separate button that updated the preview,
rather than doing it automatically.
<script language="JavaS cript" type="text/JavaScript">
The language attribute is deprecated - remove it. The type attribute is
sufficient.

[snipped function]
</script>

<form name="form2" method="post" enctype="multip art/form-data">
You should really use better names than "form2", and the like. It's good
programming practice to use descriptive names. The same goes for "myimga",
below.
<img src="images/default.gif" name="myimga" width=100 height=80
border=0>
The name attribute on IMG elements should only be used for
backward-compatibility. If NN4 support isn't an issue, use the id
attribute.
<INPUT NAME="upfile" TYPE="file" SIZE="80"
ONchange="previ ew(myimga,upfil e);">
Move this to an onclick event on a separate 'preview' button. You'll also
have to change the call to:

preview(documen t.images['imageName'],document.formN ame.upfile);

where imageName and formName are the new names of the elements, if you
decide to change them.

For future reference: in the original call, you should have used:

preview(documen t.images['myimga'],this);
<INPUT NAME="upload" TYPE="submit" VALUE="Upload">

</form>


Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Ivo
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...

<img src="images/default.gif" name="myimga" width=100 height=80
border=0>


The name attribute on IMG elements should only be used for
backward-compatibility. If NN4 support isn't an issue, use the id
attribute.


Is that so? I find the document.images collection still very well supported
among the curent browsers. So much in fact, that document.images["foo"] is
always much faster than a document.getEle mentById("foo") would be in the
same situation, plus it is less code, it is easier to type, and it reminds
of the nature of "foo".
FWIW
Ivo
Jul 20 '05 #3
"Ivo" <no@thank.you > writes:
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
The name attribute on IMG elements should only be used for
backward-compatibility. If NN4 support isn't an issue, use the id
attribute.

Is that so? I find the document.images collection still very well supported
among the curent browsers.
It should be. It is part of the W3C DOM.
So much in fact, that document.images["foo"] is always much faster
than a document.getEle mentById("foo") would be in the same
situation, plus it is less code, it is easier to type, and it
reminds of the nature of "foo".


Yes, it is great. And it works with "id" too in modern browsers and
IE, so the advice to use "id" instead of "name" is not affected by
using document.images , only by using Netscape 4 or other ancient
browsers.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Ivo
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:oe******** **@hotpop.com.. .
So much in fact, that document.images["foo"] is always much faster
than a document.getEle mentById("foo") would be in the same
situation, plus it is less code, it is easier to type, and it
reminds of the nature of "foo".
Yes, it is great. And it works with "id" too in modern browsers and
IE, so the advice to use "id" instead of "name" is not affected by
using document.images , only by using Netscape 4 or other ancient
browsers.


Aha, click, OK.
Thanks, Ivo

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2444
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save a thumbnail.jpg .... all at the same time. Links to a working example would be appreciated. Thanks.
0
2362
by: Paul Hamlington | last post by:
Hello, I've been programming in ASP for a little while now and quite an advanced user, but I have come across an unusual problem in which I need assistance. I have built my own image upload, I have two versions of the binary to string conversion one fast, one slow because some servers use chillisoft and therefore the append function in...
2
4155
by: Faree | last post by:
Hi, I am a PHP Developer.can any one help me on image upload and display of that image.what i want is uploading an image to a directory ,displaying of that image as a thumbnail.when i click on that image the image should be diplayed in another page. I wrote code for image uploading and as well as display code.but i failed in...
3
2038
by: Michael | last post by:
Hello, I want to write a componant that helps a user upload an image or file. I want something like you see on yahoo's image upload page. It has to work on mac and windows. Can anyone help me get started? Is there any sample code? Thanks, Michael
1
2251
pritipshah
by: pritipshah | last post by:
Hi All, I am using vtiger open source CRM and in that they are using FCKeditor for Image Upload (Resource browser window) but it is not upload or make new folder for image. Vtiger CRM fource to use IE for better performence so from the first day i was using IE7 for editing and testing. After some time today i tried it with Mozilla...
7
17045
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir = "photo/thumbs/"; // Path To Thumbnails Directory $twidth = "125"; // Maximum Width For Thumbnail Images
7
3723
by: dragiton | last post by:
SA Upload SQL Database variable types (image upload and storage) I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to rebuild. Does anyone have any suggestions on what I may have wrong. I am not sure if I built my table to store the picture id's correctly. Maybe a...
1
4869
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as...
26
2361
matheussousuke
by: matheussousuke | last post by:
May someone help me correct this script? there a few ' and " and ; in the wrong places: <?php include "./comm.inc"; connectdb(); $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid"; $result = @mysql_query($sql) or die(mysql_error());
3
2819
by: leelotis | last post by:
hey im trying to find a decent image upload preview and resize (for images that dont fit the placed view format) ive looked all over the web and ive had no luck and ideas?
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.