/    Sign up×
Community /Pin to ProfileBookmark

Problem submitting fileupload

Hi,

I am using a JSP file to upload a form
i am using file upload tag

I dont want to display the file upload tag ‘s text box
so what i did was i hide file upload tag and on another button click
i called file upload tag’s click event

i coulld very well browse the file
but upon form submit the fie is not getting uploaded

<input type=”file” name=”[B]form_data[/B]” style=”visibiliy:hidden”/>
<script language=”javascript”>

//Choose File
function chooseFile(){
document.getElementById(“form_data”).click();

}

</script>

The issue what i found was after the end of function the form_data tag doesn’t holds the value
is there any way in javascript to keep the file tag hold value till form gets submitted??

any help appreciated

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 12.2010 — The user has to add the file value, you are not permitted to add the value.
Copy linkTweet thisAlerts:
@harrierdhMar 12.2010 — What Fang said is correct. You cannot access or alter the file name of an upload. It is a security issue. So just put the darn box out there and live with it.
Copy linkTweet thisAlerts:
@rnd_meMar 12.2010 — make the file input 1% opacity if you don't like how it looks, but the user must PHYSICALLY click on it for it to work correctly in all browsers.
Copy linkTweet thisAlerts:
@tirnaMar 13.2010 — Regarding

The issue what i found was after the end of function the form_data tag doesn't holds the value[/QUOTE]

I only have limited experience with JSP but the html concepts are much the same.

1) Make sure you have the attribute

[CODE]
enctype="multipart/form-data"
[/CODE]


included in your <form> tag. If it's not then your file will not be uploaded.

2) if you have an onsubmit function insert at the very start of it

[CODE]
alert("Upload file name = "+document.getElementById("form_data").value);
[/CODE]


to see what, if any, file name will be uploaded.

If you change the value of:

document.getElementById("form_data").value and write it back to the form as in

var newFile = "myNewFile.ext"

document.getElementById("form_data").value = newFile;


in your onsubmit javascript, it might be accepted by the receiving server side script or it might still send the original

document.getElementById("form_data").value

but I'm not sure because I have never tried it.
×

Success!

Help @formeofme spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...