Skip to content

Commit

Permalink
Consolidating all form-relate js to form.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogenesAnalytics committed Mar 11, 2024
1 parent a9181c1 commit 7f3c8f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
23 changes: 0 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,5 @@
</div>
</noscript>
<script src="scripts/form.js"></script>
<script>
// Custom validation for select elements
document.getElementById("contact-form").addEventListener("submit", function(event) {
if (!this.checkValidity()) {
// Built-in validation failed, no need to continue
return;
}

// Custom validation for select elements
var selectElements = this.querySelectorAll("select[required]");
for (var i = 0; i < selectElements.length; i++) {
if (selectElements[i].value === "") {
event.preventDefault(); // Prevent form submission
alert("Please select an option.");

// Scroll to the element
selectElements[i].scrollIntoView({ behavior: "smooth", block: "center" });

return;
}
}
});
</script>
</body>
</html>
22 changes: 22 additions & 0 deletions scripts/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,25 @@ fetch('config.json')
.catch(error => {
handleConfigError(error);
});

// Custom validation for select elements
document.getElementById("contact-form").addEventListener("submit", function(event) {
if (!this.checkValidity()) {
// Built-in validation failed, no need to continue
return;
}

// Custom validation for select elements
var selectElements = this.querySelectorAll("select[required]");
for (var i = 0; i < selectElements.length; i++) {
if (selectElements[i].value === "") {
event.preventDefault(); // Prevent form submission
alert("Please select an option.");

// Scroll to the element
selectElements[i].scrollIntoView({ behavior: "smooth", block: "center" });

return;
}
}
});

0 comments on commit 7f3c8f8

Please sign in to comment.