Skip to content

Commit 14fbdb4

Browse files
authored
Merge pull request #392 from Ayushmaanagarwal1211/Adding-Validation
Added Rating Validation in Contact Us form
2 parents 6108b9b + ac25053 commit 14fbdb4

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

website2.0/contactus.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ body {
1010
margin-bottom: 100px;
1111
gap: 200px;
1212
}
13+
#error{
14+
color: red;
15+
font-size: 18px;
16+
text-align: center;
17+
}
1318
input::placeholder{
1419
margin: 0px;
1520
font-family: Poppins;

website2.0/contactus.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ <h1>Contact Us</h1>
127127
<span class="star" data-value="4">&#9733;</span>
128128
<span class="star" data-value="5">&#9733;</span>
129129
</div>
130-
131-
<button type="submit" id="button">Submit</button>
130+
<p id="error">Please Give Any Rating</p>
131+
<button type="submit" id="button" onclick="handleSubmit()">Submit</button>
132132
<p id="thank-you-message" style="color: white; display: none;">Thank you !!<br>We will connect soon.</p>
133133
</form>
134134
</div>
@@ -153,6 +153,22 @@ <h1>Contact Us</h1>
153153
speed: 400,
154154
});
155155
</script>
156+
157+
158+
<script>
159+
const stars = document.querySelectorAll('.star');
160+
let selectedRating = 0;
161+
162+
stars.forEach(star => {
163+
star.addEventListener('click', () => {
164+
selectedRating = star.getAttribute('data-value');
165+
});
166+
});
167+
</script>
168+
169+
<script>
170+
document.getElementById('error').style.display='none'
171+
</script>
156172
<script>
157173

158174
// if(window.innerWidth>800){

website2.0/contactus.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ document.addEventListener("DOMContentLoaded", () => {
1212
});
1313
});
1414
});
15+
16+
function handleError(){
17+
document.getElementById('error').style.display=''
18+
19+
setTimeout(()=>{
20+
document.getElementById('error').style.display='none'
21+
},2000)
22+
}
23+
24+
1525
document.getElementById('contact-form').addEventListener('submit', function(event) {
1626
event.preventDefault();
17-
27+
if(selectedRating==0){
28+
return handleError()
29+
}
1830
const thankYouMessage = document.getElementById('thank-you-message');
1931
thankYouMessage.style.display = 'block';
2032

0 commit comments

Comments
 (0)