472,983 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Writing a value to a <input type="file" name="filebox"> using Javascript

This one has really got me!

Im trying to write a value to a input type="file" form element using client-side javascript.

I have tried the obvious, simply writing:
<input type="file" name="filebox" value="myvalue">
..doesnt work (ok I sound like a newbie)

I have tried:
document.formUpload.filebox.value = "myvalue"
:(

also tried:
document.write('<input type="file" name="filebox" value="myvalue">');
:(

Does anybody know a way to do this?!

Many thanks for your time in advance!!!
Dec 27 '07 #1
3 4304
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

You can't set the default filename with JavaScript. You have to set it by selecting a file using the browse button, otherwise it could be a security risk - see this link.
Dec 27 '07 #2
Thanks for your reply. Its a pitty it is not possible with Javascript.

Is there a way to convert a normal input type="text" to a type="file"?

In this app. a user has already entered the file (via 'browse') but I need to check a few of the other fields against values in a DB, then.. if those checks are 'false', only then do I want to upload the file they initially entered. (the upload scripts are from a free resource, I do not write my own code at that level :S ). So I have carried the path value that was initailly entered to another form, and here I want to automatically enter the file value, and onload submit the form.

I am using classic asp, and client-side javascript.

Any ideas on how I can achieve this?

Thanks again for your time!
Dec 28 '07 #3
acoder
16,027 Expert Mod 8TB
Is there a way to convert a normal input type="text" to a type="file"?
Yes, by changing the type property to 'file', e.g.
Expand|Select|Wrap|Line Numbers
  1. var field = document.getElementById("IDofTextField");
  2. field.type='file';
In this app. a user has already entered the file (via 'browse') but I need to check a few of the other fields against values in a DB, then.. if those checks are 'false', only then do I want to upload the file they initially entered. (the upload scripts are from a free resource, I do not write my own code at that level :S ). So I have carried the path value that was initailly entered to another form, and here I want to automatically enter the file value, and onload submit the form.
You can make the checks with ASP and if the checks are true, just discard the file, otherwise upload it.
Dec 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
1
by: Brett | last post by:
I am writing a program that will allow a user to enter a webpage address into a form. Then it will download and display the webpage below the current one. example...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
2
by: ysuwardy | last post by:
Hello everyone, I have a question on XML with Javascript. Here is my situation: I have two xml documents (1.xml and 2.xml) with similar structure: <person> <data> <value>1</value>...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
1
by: macintoshhondo | last post by:
Hi ! i am a newbie and dont know javascript much. what i really need is a simple javascript code that can insert number in the value section of the different forms from the one form. FORM 1:...
3
by: zac540 | last post by:
Hey everyone! First of all I'd like to say that I did my best to look for any other relevant posts. The best I found was this interesting thread.. http://bytes.com/forum/thread594982.html If...
0
by: baburmm | last post by:
hello friends i want to get the footer row textbox value of the gridview using javascript for validating it. how can i get it is there any coding pls help me Thanks in advance, Regards. Babu.K
1
by: baburmm | last post by:
hello friends i want to get the footer row textbox value of the gridview using javascript for validating it. how can i get it is there any coding pls help me Thanks in advance, Regards. Babu.K
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.