473,387 Members | 1,295 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,387 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 4337
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.