Skip to content

Commit

Permalink
made responsive across all device and upgraded the CSS of the page
Browse files Browse the repository at this point in the history
  • Loading branch information
abhirajadhikary06 committed Dec 9, 2024
1 parent 89d90ca commit 20ef8da
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 175 deletions.
73 changes: 39 additions & 34 deletions Components/Forms/Feedback-Form-2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,53 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="script.js" defer></script>
<title>Enhanced Feedback Form</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.1/css/all.min.css"/>
<title>Feedback Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="modal" class="modal-content">
<span class="close">&times;</span>
<h2>FEEDBACK FORM</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<form id="feedback-form">
<div class="form-group">
<div class="icon">
<i class="fas fa-user"></i>
<div class="container">
<div id="modal" class="modal-content">
<span class="close">&times;</span>
<h2>FEEDBACK FORM</h2>
<p>We value your opinion. Share your thoughts and help us improve!</p>
<form id="feedback-form">
<div class="form-group">
<div class="icon">
<i class="fas fa-user"></i>
</div>
<input type="text" placeholder="Your Name" name="name" required>
</div>
<input type="text" placeholder="Your Name" name="name" required>
</div>
<div class="form-group">
<div class="icon">
<i class="fas fa-envelope"></i>
<div class="form-group">
<div class="icon">
<i class="fas fa-envelope"></i>
</div>
<input type="email" placeholder="Email Address" name="email" required>
</div>
<input type="email" placeholder="Email Id" name="email" required>
</div>
<div class="form-group">
<textarea cols="30" rows="5" placeholder="Your Feedback" name="feedback" required></textarea>
<div class="form-group">
<div class="icon">
<i class="fas fa-comment"></i>
</div>
<textarea placeholder="Your Detailed Feedback" name="feedback" required></textarea>
</div>
<div class="rating">
<h2>Rate Our Service:</h2>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
</div>
<button type="submit" disabled>Submit Feedback</button>
</form>
<div id="thank-you-message" style="display:none;">
Thank you for your valuable feedback!
</div>
<div class="rating">
<h2>Rate us:</h2>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<i class="rating__star far fa-star"></i>
<div id="error-message" style="display:none;">
Please complete all fields and rate us!
</div>
<button type="submit" disabled>Submit</button>
</form>
<div id="thank-you-message" style="display:none; font-size:20px; color: green; margin-top: 20px;">
Thank you for your feedback!
</div>
<div id="error-message" style="display:none; color: red;font-size:20px; margin-top: 20px;">
Please fill in all fields before submitting.
</div>
</div>
<script src="script.js"></script>
</body>
</html>
139 changes: 70 additions & 69 deletions Components/Forms/Feedback-Form-2/script.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
document.addEventListener('DOMContentLoaded', function() {
const feedbackForm = document.getElementById('feedback-form');
const submitButton = document.querySelector("#feedback-form button[type='submit']");
const thankYouMessage = document.getElementById('thank-you-message');
const errorMessage = document.getElementById('error-message');
const ratingStars = [...document.getElementsByClassName("rating__star")];
// The JavaScript remains the same as in the previous implementation
document.addEventListener('DOMContentLoaded', function() {
const feedbackForm = document.getElementById('feedback-form');
const submitButton = document.querySelector("#feedback-form button[type='submit']");
const thankYouMessage = document.getElementById('thank-you-message');
const errorMessage = document.getElementById('error-message');
const ratingStars = [...document.getElementsByClassName("rating__star")];

function allFieldsFilled() {
const inputs = feedbackForm.querySelectorAll("input[type='text'], input[type='email'], textarea");
for (let input of inputs) {
if (!input.value.trim()) {
return false;
}
}
return true;
}

function ratingSelected() {
for (let star of ratingStars) {
if (star.classList.contains('fas')) {
function allFieldsFilled() {
const inputs = feedbackForm.querySelectorAll("input[type='text'], input[type='email'], textarea");
for (let input of inputs) {
if (!input.value.trim()) {
return false;
}
}
return true;
}
}
return false;
}

feedbackForm.addEventListener('submit', function(event) {
event.preventDefault();
if (allFieldsFilled() && ratingSelected()) {
thankYouMessage.style.display = 'block';
errorMessage.style.display = 'none';
setTimeout(function() {
thankYouMessage.style.display = 'none';
}, 3000);
feedbackForm.reset();
for (let star of ratingStars) {
star.classList.remove('fas');
star.classList.add('far');
function ratingSelected() {
for (let star of ratingStars) {
if (star.classList.contains('fas')) {
return true;
}
}
return false;
}
} else {
thankYouMessage.style.display = 'none';
errorMessage.style.display = 'block';
setTimeout(function() {
errorMessage.style.display = 'none';
}, 3000);
}
});

feedbackForm.addEventListener("input", function() {
if (allFieldsFilled()) {
submitButton.removeAttribute("disabled");
} else {
submitButton.setAttribute("disabled", "disabled");
}
});
feedbackForm.addEventListener('submit', function(event) {
event.preventDefault();
if (allFieldsFilled() && ratingSelected()) {
thankYouMessage.style.display = 'block';
errorMessage.style.display = 'none';
setTimeout(function() {
thankYouMessage.style.display = 'none';
}, 3000);
feedbackForm.reset();
for (let star of ratingStars) {
star.classList.remove('fas');
star.classList.add('far');
}
} else {
thankYouMessage.style.display = 'none';
errorMessage.style.display = 'block';
setTimeout(function() {
errorMessage.style.display = 'none';
}, 3000);
}
});

function executeRating(stars) {
const starClassActive = "rating__star fas fa-star";
const starClassInactive = "rating__star far fa-star";
stars.map((star, index) => {
star.onclick = () => {
for (let i = 0; i < stars.length; ++i) {
stars[i].className = i <= index ? starClassActive : starClassInactive;
feedbackForm.addEventListener("input", function() {
if (allFieldsFilled()) {
submitButton.removeAttribute("disabled");
} else {
submitButton.setAttribute("disabled", "disabled");
}
};
});
}
});

function executeRating(stars) {
const starClassActive = "rating__star fas fa-star";
const starClassInactive = "rating__star far fa-star";
stars.map((star, index) => {
star.onclick = () => {
for (let i = 0; i < stars.length; ++i) {
stars[i].className = i <= index ? starClassActive : starClassInactive;
}
};
});
}

executeRating(ratingStars);
executeRating(ratingStars);

document.querySelector('.close').addEventListener('click', function() {
document.getElementById('modal').style.display = 'none';
});
document.querySelector('.close').addEventListener('click', function() {
document.getElementById('modal').style.display = 'none';
});

window.onclick = function(event) {
if (event.target == document.getElementById('modal')) {
document.getElementById('modal').style.display = 'none';
}
};
});
window.onclick = function(event) {
if (event.target == document.getElementById('modal')) {
document.getElementById('modal').style.display = 'none';
}
};
});
Loading

0 comments on commit 20ef8da

Please sign in to comment.