Skip to content
Advertisement

Resize Image from Client-side for multiple HTML input

I find this helpful article for resizing images before uploading them to the server. I want to use it for some repetitive HTML input but I’m having a problem altering the javascript code since I’m not really good in javascript.

This is what I’ve tried so far. But as can see, I didn’t get the value for that imagefiles

JavaScript
JavaScript

How can I alter this code to be able to resize the images from multiple input file and then send to PHP side?

Advertisement

Answer

That’s because you are mixing the name and class attributes when you create your HTML code. Instead of:

JavaScript

it should read …

JavaScript

If you want to receive the proper instructionsid when you post the files back to the server, I would recommend to create a loop similar to this one:

JavaScript

Your JS code will also need some rewrites as it contains several errors (i.e. document.getElementsByClassName('inp_img[i]').value = ''; searches for an element like <input class="inp_img[i]">, the i needs to be escaped properly).

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement