Jump to content
  • 0

Is there a way to restrict the file upload field to only take a .fdr, .txt, .pdf, pdf, .png, .mp4, mp3, .wavi file type document? Can this be achieved in javascript?


Cherry
 Share

Question

Hi everyone, is there a to restrict the file upload field to only take the ff. file type of document? Can this be achieved in JavaScript/CSS? Need some help. Thank you

Asst Type:  Files Accepted:
Story:             .word, .fdr. .txt, .pdf
Visual Art:   .pdf, .png. (photo image)
Movie:           .mp4
Music:           .mp3, .wavi
Other (Request file type upload)

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi - Just wanted to share this solution. If you want to restrict file type in multiple fields, just like in this article: https://howto.caspio.com/tech-tips-and-articles/advanced-customizations/restrict-file-types-that-can-be-uploaded-in-a-datapage/

You can use this code:

<script type="text/javascript">

var files = Array.from(document.querySelectorAll('#InsertRecordFIELDNAME1, #InsertRecordFIELDNAME2, #InsertRecordFIELDNAME3, #InsertRecordFIELDNAME4, #InsertRecordFIELDNAME5'));

var extensions = ['pdf']; // you can add other file types here

files.forEach(function(el) {
el.addEventListener('change', function(e) {

var ext = this.value.match(/.([^.]+)$/)[1];

if (!extensions.includes(ext)){

alert('Invalid file format. Please upload PDF only.');

this.value = '';

}
});});

</script>

Hope it helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...