Design comparison
Solution retrospective
On JavaScript Code I need feedback.
Community feedback
- @filipjuszczakPosted 5 months ago
Hi!
You could use data attributes on your buttons and access the associated values in JavaScript rather than rely on
innerHTML
, like this:<button class="btn active" data-value="1">1</button>
let value = e.target.dataset.value;
You might also want to prevent user from submitting if they didn't select a rating - you could do that by adding a
disabled
attribute to the button with a default value oftrue
and after the user selected a rating, set the attribute tofalse
or in the submit event listener early return if rating was not selected (you would need an additional variable, e.g.selectedRating
, to store that information), then use it in the handler:const selectedRating; submit.addEventListener("click", () => { if (!selectedRating) return; ... });
Marked as helpful0@sameermandvePosted 5 months ago@filipjuszczak Thanks I will try to implement it!!
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord