// script.
js
function validateForm(form) {
let isValid = true;
// Example: Validate a text input named 'name'
const nameInput = [Link]('input[name="name"]');
if (nameInput && [Link]() === '') {
alert('Name field cannot be empty in ' + [Link]);
isValid = false;
// Example: Validate an email input named 'email'
const emailInput = [Link]('input[name="email"]');
if (emailInput && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test([Link])) {
alert('Please enter a valid email in ' + [Link]);
isValid = false;
// Add more validation rules as needed for different field types and requirements
return isValid;
}
<!-- [Link] -->
<form id="form1" onsubmit="return validateForm(this);">
<label for="name1">Name:</label>
<input type="text" id="name1" name="name">
<label for="email1">Email:</label>
<input type="email" id="email1" name="email">
<button type="submit">Submit Form 1</button>
</form>
<form id="form2" onsubmit="return validateForm(this);">
<label for="name2">Name:</label>
<input type="text" id="name2" name="name">
<label for="email2">Email:</label>
<input type="email" id="email2" name="email">
<button type="submit">Submit Form 2</button>
</form>
<script src="[Link]"></script>