Skip to content
Advertisement

i receive the output value of radio buttons as both on even though one is checked

I only did this code of java script

so maybe I need to do an add event listener but i don’t know what I need to do

JavaScript
JavaScript

i want so that one of them be on if checked and off if its not checked how can i do that?

html

JavaScript

ps I already tried adding value of 1 and 2 to html code but it only gives 1 and 2 regardless that its not checked

Advertisement

Answer

In order to see if a radio button is selected or not, you should use the .checked attribute.

JavaScript

For value, you could add the attribute value="delivery" in order to know what is checked without knowing it’s id.

Here’s a piece of code how it works:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement