Forum Discussion
SiniWickramasin
6 years agoQrew Cadet
Hi Dan,
I tried this method and it worked great for one file attachment field. However my requirement is a bit different. I have a form with multiple fields with file attachments. Example Photo1, Photo2, Photo3 etc. Ideally when the users click on either one of the "browse" buttons to locate image file and if the file is more than 1Mb, I would like to stop them from uploading. I'm very new to JS so having troubles applying this method. Any advice would be greatly appreciated!!!
Many thanks in advance!
I tried this method and it worked great for one file attachment field. However my requirement is a bit different. I have a form with multiple fields with file attachments. Example Photo1, Photo2, Photo3 etc. Ideally when the users click on either one of the "browse" buttons to locate image file and if the file is more than 1Mb, I would like to stop them from uploading. I'm very new to JS so having troubles applying this method. Any advice would be greatly appreciated!!!
Many thanks in advance!
- AustinK6 years agoQrew CommanderThe part that matters the most is the first line inside the bit that says "#_fid_6" you would just change that to be whatever field you wanted but it must go by the field id(FID.) You can have multiple selectors in jquery and can do it this way. This will watch all 3 fields for changes and alert if the file size is not 1000... bytes? Whatever it is.
$("#_fid_6,#_fid_7,#_fid_8").on("change", function(e) { var maxSize = 1000; var data = e.originalEvent.target.files[0]; if (data.size > maxSize) { alert('Your file size is ${data.size}. Please select a smaller file.'); this.value = ""; } });
You are going to have to fix the indentation. QuickBase has absolutely ruined this and it's actually very difficult to get posted in one code box. - SiniWickramasin6 years agoQrew CadetHi AustinK, I tested your suggestion and it worked like a charm. Its people like you and Dan (and alike) who are the real everyday heroes even if you think the input is small!!! Its the willing to help that really makes the world a better place : )
- SiniWickramasin6 years agoQrew CadetHi Dan,
As per my previous message this works great on Chrome browser but for some reason its not working on IE. I have checked if Active Scripting and is enabled in IE under security settings and it is enabled......Really hoping there is a way around it.... - AustinK6 years agoQrew CommanderWhich version of IE are you testing this on? An unfortunate side effect of having so many browsers available is not everything works on every version. In general Chrome and Firefox should work with most things but it again depends on the version. It can also depend on the version of the library you are using, if the command is from a library. QuickBase uses jQuery 1.7.2 which is older, as an example.
If you are using Internet Explorer 10 or 11 that works with a lot of things but still is not ideal. If you were using Edge that would be better but Chrome supports a lot of stuff.
I've stopped supporting IE. Trying to make something that isn't a native function work in all browsers is sometimes impossible. I know it isn't always an option but just having your users only use Chrome or Firefox or whatever as long as users stuck with one option would solve that.
You could go through the javascript above line by line and see which line is causing the error, or you could check in console to see which line is giving you an error and report back here. That would tell me more about what is going on with it.