In your code you have set the value of the button to Add which simply means that the text that will appear on the button is Add. Value, as an attribute sets the text of that element.
If you want to access that element by id, you need to specify an id attribute for it, like this:
<input id="Add" class="inputbutton" type="button" value="Add">
And to access the button you could simply use the code that you have used in your post:
document.getElementById('Add').click();
Also, if you do not want to modify your current code, you could simply use another javascript selector to get that specific element, such as:
document.getElementsByClassName('inputbutton')[0].click();
Moreover, if you want to add click event listeners for the other elements, as you do for the Add button, you could do some Event Delegation which is great to manage performance:
// Bind the event listener to the top most element that contains your event targets
document.addEventListener('click', function(event){
// Get target of the event
var target = event.target || event.srcElement;
switch(target.value) {
case('Add'):
alert('Add button clicked!');
break;
...
// Add cases for the other buttons as well
}
});
Here is a simpler version that only listens for clicks on the Add button:
document.addEventListener('click', function(event){
var target = event.target || event.srcElement;
if (target.value == 'Add') {
alert('You clicked?');
}
});
getElementbyId()to fetch it