Question regarding name parameter in input file

For the following code mentioned here :

<div>
   <label for="file">Choose file to upload</label>
   <input type="file" id="file" name="file" multiple>
 </div>

Is it mandatory to have the name parameter which is file same as the id parameter? I am sure that for and id values need to be same, but I am wondering if the following is possible?

<div>
   <label for="file">Choose file to upload</label>
   <input type="file" id="file" name="firstFile" multiple>
 </div>

Is firstFile allowed if I have to use that in Javascript something like this :

formData.append('firstFile', $('input[type=file]')[0].files[0]);

Hi @Jack_Tauson_Sr, it is not mandatory that the name and id attributes are the same. The name attribute specifies the key in which that value will reside in the posted data array. The id will let you select the HTML input in the DOM.

Hope that helped,

Andres

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.