How to input variable inside regex javascript?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.