Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 18th, 2004, 07:07 PM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default define location for file input tag

I asked this question in the other forum but didn't get any replies so I figured I'll try here. What I'm trying to do:

I have a form with a input element, type file. What I want to happen when a user clicks the Browse button to go get a file is for the "Choose File" dialog to open to a specified location defined by the script. For instance:

<form...>
<input name="Pic" type="file" onClick="getPic()">
</form>

in head...
function getPic() {
  myElement = document.form.Pic;
  path = "ftp://ftpsite/pictures/";
  myElement.value = path;
}

Is it possible to do this? If so, does anyone know how to achieve it?

thanx,
Bob


Reply With Quote
  #2 (permalink)  
Old August 19th, 2004, 12:51 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Fortunately, you can't set the value of a file control.
Combined with this body tag:

<body onload="document.forms[0].submit();">

you could easily steal any documents you want, provided you'd know the name.

You also cannot upload from an FTP site. The input type="file" control uses a local or network path, but AFAIK, you cannot get it to upload files from an FTP server.

What exactly are you trying to accomplish?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old August 19th, 2004, 01:12 PM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Fortunately, you can't set the value of a file control.
Combined with this body tag:

<body onload="document.forms[0].submit();">

you could easily steal any documents you want, provided you'd know the name.

You also cannot upload from an FTP site. The input type="file" control uses a local or network path, but AFAIK, you cannot get it to upload files from an FTP server.

What exactly are you trying to accomplish?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

Thanks for responding. I didn't want to define an actual file name, just a directory, but that may not make a difference.

What I'm doing is for an Intranet, it's a quality control program that the qc person uses to enter certain info on the item their checking, including a picture if there's a problem. I have a form that collects information and a picture, and enters into a database. I didn't want to actually store the pic in the database (to keep the db size down and for ease) so I was planing to store the path to the picture. The pictures would be stored on a network drive in a folder. The user would use the file browse to go find the picture and then I just pass the path to the database. I didn't want the user to have to go and search the network for the path, especially on thin clients where I can't map drives, so I thought the solution would be to force the file open dialog to open to the folder where the pics are stored and then the user just has to pick the picture.

What would be really nice is if it's possible to tie a button on the form to the camera attached to the computer - just a little web cam, and when the qc person selects the button the picture is taken and entered into the form automatically - then I'll just stick the pictures themselves into the database. I don't know if that's possible, haven't looked into it yet.

Let me know what you think and if you have any other suggestions.

Thanks!
Bob


Reply With Quote
  #4 (permalink)  
Old August 20th, 2004, 12:20 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Bob,

Although you cannot set the value of the <input type="file"> control, you can read from it.

What you could do is write a little JavaScript function that retrieves the value from the file field, and stores it in a hidden field. You can call this function on onblur of the file field, or when the user clicks a submit button, for example.

Then, at the server, you can retrieve the name of the file from the hidden field. You may need to reset the file field to prevent the actual upload of the file.

You can only have a user select a real file, not a folder. So, unfortunately, when you want your users to select a folder, you'll have to make them point to a file inside that folder, and then at the server extract the folder name from the file name.

With normal HTML, you cannot retrieve a picture from a camera. Maybe if you write an ActiveX control, you could do it, but I haven't tried
anything like that before.

If you need help with the JavaScript solution, let me know.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #5 (permalink)  
Old August 20th, 2004, 09:00 PM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi Bob,

Although you cannot set the value of the <input type="file"> control, you can read from it.

What you could do is write a little JavaScript function that retrieves the value from the file field, and stores it in a hidden field. You can call this function on onblur of the file field, or when the user clicks a submit button, for example.

Then, at the server, you can retrieve the name of the file from the hidden field. You may need to reset the file field to prevent the actual upload of the file.

You can only have a user select a real file, not a folder. So, unfortunately, when you want your users to select a folder, you'll have to make them point to a file inside that folder, and then at the server extract the folder name from the file name.

With normal HTML, you cannot retrieve a picture from a camera. Maybe if you write an ActiveX control, you could do it, but I haven't tried
anything like that before.

If you need help with the JavaScript solution, let me know.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

I'd prefer to get the picture directly from a camera than using the file browse. I'd also rather use javascript that activex, so if you have a solution for this I would be very interested in it!

Thank you!
Bob

Reply With Quote
  #6 (permalink)  
Old August 21st, 2004, 01:53 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Unfortunately, with "JavaScript solution" I was referring to getting the file name from a file control, which I mentioned first in my post.

Getting a picture directly from a camera cannot be done with "regular Web languages" like HTML or JavaScript. You'll need to use other technologies like ActiveX or maybe Java.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #7 (permalink)  
Old August 21st, 2004, 09:47 AM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Unfortunately, with "JavaScript solution" I was referring to getting the file name from a file control, which I mentioned first in my post.

Getting a picture directly from a camera cannot be done with "regular Web languages" like HTML or JavaScript. You'll need to use other technologies like ActiveX or maybe Java.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

Ok, that's what I was afraid of - I guess it's on to ActiveX. Thank you so much for your help :)

Bob

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xhtml input tag not rendered correctly by xslt dude153 XSLT 4 December 14th, 2007 02:04 PM
dynamic <input> tag Val Javascript 1 September 6th, 2006 02:55 AM
VBSCRIPT in between JAVASCRIPT and an INPUT TAG Pr shookim Javascript 2 February 13th, 2006 10:48 AM
defining location for input type file bleitner Javascript How-To 1 August 24th, 2004 08:15 AM



All times are GMT -4. The time now is 11:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.