JavaScript clearing file input field when adding to the parent element.?
-
Okay so I have this HTML: <div> <p id="defaultfiles">Select a file: <input type="file" name="files[]" onchange="chkFlTp(this)"></p> </div> <div id="extrafiles"> </div> And this JavaScript: var cnt = 1; function chkFlTp(el) { if(/\.(php)|(asp)|(cgi)|(pl)$/.test(e… { alert('Script files are now allowed.'); el.value = ''; } else { alert(el.value); var text = document.getElementById('defaultfiles').… extras = '<p id="pz'+cnt+'">'+text+' <a href="javascript:void(0)" onclick="document.getElementById(\'pz'+c… document.getElementById('extrafiles'… += extras; cnt++; alert(el.value); } } Basically what it's supposed to do is when a user selects a file to upload, it automatically adds another upload field so that can upload multiple files. Well that part works fine, but when this line runs: document.getElementById('extrafiles').… += extras; it clears out the input fields (all except for the one in the first input field. You can see an example here: http://csi-companies.com/uploadtool
-
Answer:
This is just a thumb suck, but why not have them in there already, and set the styling, with JavaScript to be 'hidden' when the page loads, and then each submission simply changes the next input to no longer be hidden. You could put in 10 or so by default. It also means that nobody can come along and just load file after file, because you set a limit naturally? Just an idea.
Mark at Yahoo! Answers Visit the source
Related Q & A:
- How to return a value from .ashx file to javascript in a variable?Best solution by forums.asp.net
- How Add element to XML file?Best solution by Stack Overflow
- How to skip the input in batch file?Best solution by Stack Overflow
- How I can validate input on form before upload file?Best solution by stackoverflow.com
- How set input file in Jquery?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.