I have a form where I upload three different files. Also I have two input fields for all file uploads where I store some information on file upload.
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> .
</script>
<div>
<input type="file" class="file_name" name="file_name[]"onchange="getFileData(this);" />
<input type="text" class="file_name_helper" name="file_name_helper[]"/>
<input type="text" class="duration" name="duration[]"/>
</div>
<div>
<input type="file" class="file_name" name="file_name[]" onchange="getFileData(this);" />
<input type="text" class="file_name_helper" name="file_name_helper[]" />
<input type="text" class="duration" name="duration[]"/>
</div>
<div>
<input type="file" class="file_name" name="file_name[]" onchange="getFileData(this);"/>
<input type="text" class="file_name_helper" name="file_name_helper" />
<input type="text" class="duration" name="duration[]"/>
</div>
<script type="text/javascript">
function getFileData(myFile){
var file = myFile.files[0];
var filename = [file.name];
$(myFile).next("input[name='file_name_helper[]']").val(filename);
$("input[name='duration[]']").val("duration");
}
</script>
The problem is that when I upload the form, the first field "file_name_helper" gets populated correctly with the selector that I have but when I do the same for the "duration" field it doesn't work. How can I choose the specific duration field? Any help would be appreciated