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•3y 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
son arg
son argOP•3y ago
Okay, done Works! Thanks! 🙂
13eck
13eck•3y 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.
son arg
son argOP•3y ago
What's radix btw?
13eck
13eck•3y ago
radix is the base. Base 2 is binary, base 10 is decimal (what we normally use), base 16 is hexadecimal, etc.
son arg
son argOP•3y ago
Oh okay
13eck
13eck•3y 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
son arg
son argOP•3y ago
Thanks! 🙂
Want results from more Discord servers?
Add your server