I’m having issues with JavaScript not detecting the click event on a button. Here is my HTML code:
<input type="button" value="Upload" id="filemanagement_uploadbutton[0]" name="filemanagement_uploadbutton" onclick="javascript:uploadFiles();">
Here is my JavaScript code (with console.log commands for error checking):
let fileButtons = document.getElementsByName('filemanagement_uploadbutton');
console.log(fileButtons.length); //returns 2, since I have two buttons
console.log(fileButtons[0].id); //returns filemanagement_uploadbutton[0]
console.log(fileButtons[0].type); //returns button
console.log(fileButtons[0].click); //returns javascript:uploadFiles();
fileButtons[0].click();
I’ve also tried:
let fileButton = document.getElementsByName('filemanagement_uploadbutton')[0];
fileButton.click();
Both of these result in the error:
Uncaught TypeError: fileButtons[0].click is not a function
or
Uncaught TypeError: fileButton.click is not a function
How is it telling me that click is not a function on the element that it’s telling me the click function is “javascript:uploadFiles();” literally one element above?
Any insights? Thanks!