Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Design

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 21-04-2004, 05:24 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Question How to do INSTANT image preview on Mozilla?

well... I am creating a image upload form and there is a image preview area. User can preview the image after selecting image file from a File browse.

I got it works on Internet Explorer but it not on Mozilla(not tested on Netscape, anyway).

Here is my code, plain html and javascript only:
PHP Code:
<html>
<
head>
<
title>Upload Photo</title>
<
script>
function 
changePhoto() {
    
document['tempPic'].src document.form1.picPath.value;
}
</script>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<img name="tempPic"> 
  <input type="file" name="picPath" onChange="changePhoto();">
  <input type="submit" name="upload" value="Upload">
</form>
</body>
</html> 
I found that Mozilla's onChange event act differently than IE's, and it seems like does not work on type="file" input...

Anybody has any idea to make it works on Mozilla/Netscape?
Thank you in advance.
__________________
LiewCF | Malaysia Bloggers Forum

Last edited by lcf; 21-04-2004 at 05:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 21-04-2004, 10:10 PM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 768
Rep Power: 100
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
$me x guna mozilla
x amik tau pun pasal mozilla ke godzilla ke
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 21-04-2004, 11:10 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
it is open source browser. The best browser for OpenSource OS like Linux.
Official website: http://www.mozilla.org
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 22-04-2004, 09:38 AM
Inspired Webmaster
 
Join Date: Feb 2004
Location: Shah Alam
Posts: 175
Rep Power: 60
hftey is on a distinguished road
Send a message via ICQ to hftey Send a message via MSN to hftey Send a message via Yahoo to hftey Send a message via Skype™ to hftey
I dont think it will work for mozilla. I have the same thing on the website I am working on and it only work for IE. I have not tested whether it is regarding onchange but I do know type="file" have some security restriction and things like set the type="file" with initial value can not be done either IE or Mozilla/Netscape.
__________________
Venzon Solution Services
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 22-04-2004, 12:44 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
I know the code does not work on Mozilla, just wonder is there any alternative way to do the same thing in Mozilla or not... :/

Btw, according to W3.org:
Quote:
...User agents may use the value of the value attribute as the initial file name.
Link: http://www.w3.org/TR/html401/interac....html#h-17.4.1
Dunno how come it does not work, IE and Mozilla no follow W3?
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 22-04-2004, 12:51 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Addition info about type=file

- security risk for initial value on type=file: http://www.insecure.org/sploits/nets...type.file.html

Mozilla ignore the value: http://www.geocrawler.com/archives/3...2/4/0/8331991/

Guess IE also ignore the value as well.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 25-04-2004, 06:30 PM
BasicCX's Avatar
Novice Webmaster
 
Join Date: Apr 2004
Location: Cheras, Selangor.
Posts: 92
Rep Power: 56
BasicCX is on a distinguished road
Send a message via Yahoo to BasicCX
I will study the code for a while. i think there are solution for this.
__________________
Check out: http://www.xpodonline.com
Hosting & Domain: http://www.cubiex.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 25-04-2004, 10:41 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
ok. wait for your good news
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 26-04-2004, 01:14 AM
BasicCX's Avatar
Novice Webmaster
 
Join Date: Apr 2004
Location: Cheras, Selangor.
Posts: 92
Rep Power: 56
BasicCX is on a distinguished road
Send a message via Yahoo to BasicCX
hey lcf. try change to

document.images.tempPic.src = "file:///"+document.form1.picPath.value;

I don't have Mozilla to test.
__________________
Check out: http://www.xpodonline.com
Hosting & Domain: http://www.cubiex.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 26-04-2004, 01:54 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
well, I can tell you it does not work. I have tried.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 26-04-2004, 09:23 AM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 95
sufyan is on a distinguished road
You need to stripslashes for it to work in mozilla

For example (hardcoded):

The following won't work:
Code:
<script>

function changePhoto() {
document['tempPic'].src = "file:///C:\dir1\dir2\somepic.jpg";

}
</script>

However, the following will work in Mozilla:
Code:
<script>

function changePhoto() {
document['tempPic'].src = "file:///C:\\dir1\\dir2\\somepic.jpg";

}
</script>
So basically, you just have to figure out how to strip slashes. Hope this helps.

Quote:
it is open source browser. The best browser for OpenSource OS like Linux.
Official website: http://www.mozilla.org
Mozilla rocks!

Basically, in my opinion, if something works in Mozilla, it will work in IE. The Mozilla browser follows the recommendation of the W3C very tightly. IE is very loose on standards.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 26-04-2004, 12:18 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Thank you sufyan. I will try it now.

Quote:
Originally posted by sufyan
Basically, in my opinion, if something works in Mozilla, it will work in IE. The Mozilla browser follows the recommendation of the W3C very tightly. IE is very loose on standards.
Ya, right. But something works in IE, it may not works in Mozilla, because IE does not follow the standards...
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 26-04-2004, 02:06 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Code:
<script>

function changePhoto() {
document['tempPic'].src = "file:///C:\\dir1\\dir2\\somepic.jpg";

}
</script>
Sorry to say that, this does not work on Mozilla. Well, at least not work on "Browse..." button. I suspect it does not strike the "onChange" event on "Browse..." button in Mozilla.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 26-04-2004, 05:06 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 95
sufyan is on a distinguished road
Interesting... how about try throwing in a preview button?

Code:
<html>
<head>
<title>Upload Photo</title>
<script>
function changePhoto() {
document['tempPic'].src = "file:///C:\\Documents and Settings\\Sufyan\\My Documents\\My Received Files\\gfhfgh.JPG";

}
</script>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<img name="tempPic"> 
  <input type="file" name="picPath">
  <input type="button" name="preview" value="Preview Image" onClick="changePhoto();">
  <input type="submit" name="upload" value="Upload">

</form>
</body>

</html>
See how that goes. I'v tested it with Firebird 0.8 and it works fine (for me)...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 26-04-2004, 05:44 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
no problem with preview button.

So, shall we conclude that Mozilla does not fire onChange event on "Browse..." button?

And here is the workaround code for both IE and Mozilla:
Code:
<html>
<head>
<title>Upload Photo</title>
<script>
function changePhoto() {
	document['tempPic'].src = "file:///" + document.form1.picPath.value;
}
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<img name="tempPic"> 
  <input type="file" name="picPath" onChange="changePhoto();">
  <input type="button" name="preview" value="Preview Image" onClick="changePhoto();">
  <input type="submit" name="upload" value="Upload">

</form>
</body>

</html>
Thank you, everyone
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

«