submit form button click via js code example
Example 1: html submit form onclick
var form = document.getElementById("form-id");
document.getElementById("your-id").addEventListener("click", function () {
form.submit();
});
Example 2: javascript submit a form with id
var form = document.getElementById("myAwsomeForm");
document.getElementById("your-link-or-button-id").addEventListener("click", function () {
form.submit();
});
document.getElementById('myAwsomeForm').submit();
Example 3: how to create a form without a submit button javascript
<form id="myFunction" onClick= { myFunction } >
<input type="file" name="fileToUpload" id="myFunction" />
</form>
function myFunction() {
document.getElementById("myFunction").submit();
}
Example 4: halt button from submitting js
cell2.innerHTML = "<button type='button' class='remove-condition' onclick='removeCondition()'>X</button></td>";