We're developing a plug-in to check the filenames for invalid characters when the client does an upload. Very simple really, but I can't get the JavaScript to work properly. I've tried:
1. putting it outside the form which doesn't work
2. inside a <script></script> tag which doesn't work
3. injecting into the header of the CKFinder document which doesn't give me a DOM object
My code looks like this:
Which should work, at least it does outside of CKFinder. I'm calling the function from a button on the form using:
Any suggestions would really be appreciated.
1. putting it outside the form which doesn't work
2. inside a <script></script> tag which doesn't work
3. injecting into the header of the CKFinder document which doesn't give me a DOM object
My code looks like this:
function checkFilename() { var regex = new RegExp('^[-_a-zA-Z0-9]+\.[a-zA-Z]{3}$'); var result = regex.exec(document.getElementById('upload').value); if(result == null) { document.getElementById('error_msg').style.display = 'block'; } else { document.forms["upload_form"].submit(); } }
Which should work, at least it does outside of CKFinder. I'm calling the function from a button on the form using:
<input type="button" value="Upload File" onclick="checkFilename();" />
Any suggestions would really be appreciated.