+ 1
try this <input type="button" value="Submit" onclick="submitForm()"> You will need to either use array based notation or use document.getElementById() / document.getElementsByName(). The getElementById() function returns the element instance directly as Id is unique (but it requires an Id to be set). The getElementsByName() returns an array of values that have the same name. In this instance as we have not set an id, we can use the getElementsByName with index 0. function submitForm() { // Get the first form with the name // Usually the form name is not repeated // but duplicate names are possible in HTML // Therefore to work around the issue, enforce the correct index var frm = document.getElementsByName('contact-form')[0]; frm.submit(); // Submit the form frm.reset(); // Reset all form data return false; // Prevent page refresh }
1st Feb 2022, 10:43 PM
ElSirGuti
ElSirGuti - avatar