Frontend Mentor Help

How can I have the active styling stay focused when clicked, and also how can I store the value in the li when the user clicks submit? Code: https://jsfiddle.net/e36dztjo/2/
13 Replies
argbet
argbet2y ago
I used li's because I couldn't get the right styling on radio buttons. The only thing I could style were their width
Jochem
Jochem2y ago
you'd probably want to hide the radio buttons, and have the li's like this
<li>
<label for="rating5">5</label>
<input type="radio" name="rating" id="rating5" value="/>
</li>
<li>
<label for="rating5">5</label>
<input type="radio" name="rating" id="rating5" value="/>
</li>
MarkBoots
MarkBoots2y ago
check out Kevins latest video (yesterday). he did style the radio buttons in that there are different ways to do it. here a quick fiddle, based on what kevin did https://codepen.io/MarkBoots/pen/mdKPeVE
Mannix
Mannix2y ago
yeah radio buttons with labels seems the best choice
MarkBoots
MarkBoots2y ago
also added the js logic
argbet
argbet2y ago
Thanks, guys!
argbet
argbet2y ago
Could you please explain line 5 and the highlighted red or possibly link to a resource?
MarkBoots
MarkBoots2y ago
it is the same as
function handleRating(event){
const form = event.currentTarget;
const rating = parseInt(new FormData(form).get("rating"));
console.log(rating)
}
function handleRating(event){
const form = event.currentTarget;
const rating = parseInt(new FormData(form).get("rating"));
console.log(rating)
}
event is an object from the listener that holds the 'currentTarget', I destructured it ({currentTarget}) it already as the parameter, and renamed it as 'form' ({currentTarget:form})
argbet
argbet2y ago
Oh okay And line 5 gets the rating through some sort of get method?
MarkBoots
MarkBoots2y ago
FormData() - Web APIs | MDN
The FormData() constructor creates a new FormData object.
argbet
argbet2y ago
What's new FormData btw Oh okay, perfect, thanks!
MarkBoots
MarkBoots2y ago
get("rating") is "name=rating" atrribute in the html input element
argbet
argbet2y ago
Hey, quick question, is it better to use your method to submit a form using JS, or is it better to submit a form inside the HTML itself?
Want results from more Discord servers?
Add your server