Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added character count field in Contact page #1705

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions assets/contact/contact.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ textarea:hover {
color: rgb(255, 255, 255);
margin-bottom: 0;
}

.char-count {
text-align: right;
font-size: 10px;
color: #999;
margin-top: -15px;
margin-bottom: 10px;
}



4 changes: 3 additions & 1 deletion assets/contact/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ <h2>Contact Us</h2>
<input type="email" id="email" name="email" placeholder="Enter Your Email" required oninput="validateEmail('email')">

<label for="message">Your Message:</label>
<textarea id="message" name="message" rows="5" placeholder="Enter Your Message" required></textarea>
<textarea id="message" name="message" rows="5" placeholder="Enter Your Message Atleast 50 Characters" required></textarea>
<div id="charCount" style="font-size: 1.5em; font-weight: bold; margin-top: 10px;">Message Count: 0/50</div>


<button type="submit">Send Message</button>
</form>
Expand Down
57 changes: 34 additions & 23 deletions assets/contact/contact.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
function validateName(inputId) {
let input = document.getElementById(inputId);
let value = input.value;
let regex = /^[A-Za-z ]+$/;

if (!regex.test(value)) {
alert("Please enter only characters in the name field.");
input.value = value.replace(/[^A-Za-z ]/g, ''); // Remove any non-alphabetic characters
}
}

const ham = document.querySelector(".hamburger");
const navMe = document.querySelector(".nav-menu");

// Hamburger menu
ham.addEventListener("click", mobileMenu);
function mobileMenu() {
ham.classList.toggle("active");
navMe.classList.toggle("active");
}

// text message length not less than 50 chars
document.addEventListener('DOMContentLoaded', function() {
const contactForm = document.getElementById('contact-form');
const messageInput = document.getElementById('message');
const charCount = document.getElementById('charCount');
const minLength = 50; // Minimum length for the message

messageInput.addEventListener('input', function() {
const currentLength = messageInput.value.length;
charCount.textContent = `Message Count: ${currentLength}/${minLength}`;
if (currentLength < minLength) {
charCount.style.color = 'red';
} else {
charCount.style.color = 'green';
}
});

contactForm.addEventListener('submit', function(event) {
if (messageInput.value.length < 50) {
if (messageInput.value.length < minLength) {
event.preventDefault();
alert('Your message must be at least 50 characters long.');
}
});
});

function validateName(inputId) {
let input = document.getElementById(inputId);
let value = input.value;
let regex = /^[A-Za-z ]+$/;

if (!regex.test(value)) {
alert("Please enter only characters in the name field.");
input.value = value.replace(/[^A-Za-z ]/g, ''); // Remove any non-alphabetic characters
}
}

function validateEmail(emailFieldId) {
const emailField = document.getElementById(emailFieldId);
const emailPattern = /^[a-zA-Z0-9._%+-]+@gmail\.com$/;
Expand All @@ -41,3 +42,13 @@ function validateEmail(emailFieldId) {
emailField.setCustomValidity("");
}
}

const ham = document.querySelector(".hamburger");
const navMe = document.querySelector(".nav-menu");

// Hamburger menu
ham.addEventListener("click", mobileMenu);
function mobileMenu() {
ham.classList.toggle("active");
navMe.classList.toggle("active");
}