27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
export class AutoSubmit extends HTMLFormElement{
|
|
connectedCallback() {
|
|
const form = this; // Reference to the form element
|
|
|
|
// Get all input elements within this form
|
|
// We're interested in text, number, and other common input types
|
|
const inputs = form.querySelectorAll('input:not([type="submit"]):not([type="button"]):not([type="reset"]), select, textarea');
|
|
|
|
// Add an event listener to each input element
|
|
inputs.forEach(input => {
|
|
input.addEventListener('input', () => {
|
|
// Display a message that the form is being submitted
|
|
const messageBox = document.getElementById('submissionMessage');
|
|
if (messageBox) {
|
|
messageBox.style.display = 'block';
|
|
messageBox.textContent = 'Form submitted automatically!';
|
|
// Optionally hide the message after a short delay
|
|
setTimeout(() => {
|
|
messageBox.style.display = 'none';
|
|
}, 2000);
|
|
}
|
|
form.submit();
|
|
});
|
|
});
|
|
}
|
|
}
|