How to get data from radio button to JS?

Hi, using the FormData API, I got NaN Code: https://jsfiddle.net/cs6qphtr/3/
8 Replies
Jochem
Jochem•2y ago
gotta add a value attribute to the radio buttons you probably want value="1" for the first one, value="2" for the second, and so on
argbet
argbet•2y ago
Okay, done Works! Thanks! 🙂
13eck
13eck•2y ago
Need val…dangit @jochemm ! ::shakes fist in impotent rage:: Also, you can clean it up a bit:
const form = new FormData(this);
const rating = parseInt(form.get("rating"),10);
const form = new FormData(this);
const rating = parseInt(form.get("rating"),10);
Since this is the form that the event is being called on. And it's always good to remember to pass in the radix for parseInt. If you don't want to use the radix then Number() would work.
argbet
argbet•2y ago
What's radix btw?
13eck
13eck•2y ago
radix is the base. Base 2 is binary, base 10 is decimal (what we normally use), base 16 is hexadecimal, etc.
argbet
argbet•2y ago
Oh okay
13eck
13eck•2y ago
In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers. For example, for the decimal/denary system (the most common system in use today) the radix (base number) is ten, because it uses the ten digits from 0 through 9.
–https://en.wikipedia.org/wiki/Radix TIL vigesimal is base-20
argbet
argbet•2y ago
Thanks! 🙂
Want results from more Discord servers?
Add your server