-1

I'm trying to learn more (in depth) Javascript. My first problem would be how to get Javascript to console log "Clicked" when a radio button in the Html index is clicked. Pretty basic but i'm still a basic.

This is just for learning purposes. I'm having issues understanding the javascript syntax.

document.getElementsBytype("radio").addEventListener("click") {
  console.log("clicked");
}
<!DOCType>
<html>

<head>
  <meta charset="utf-8">
  <title> </title>
  <script src="script.js">
  </script>
</head>

<body>
  <form>
    <input type='radio' name="gender" value="male">Male<br>
    <input type='radio' name="gender" value="Female">Female<br>
    <input type='radio' name="gender" value="Other">Other<br>
  </form>
</body>

</html>
Rob
  • 14,746
  • 28
  • 47
  • 65
  • 1
    First `getElementsBytype` is wrong. There is no method like that and how you use addEventListener is wrong. There is `getElementsByTagName` which returns collections. You would be better off with `querySelectorAll('[type="radio"]')` but how you add the events is wrong. – epascarello Sep 04 '19 at 16:52
  • It doesn't work at all. There's no function `getElementsBytype`, you're missing a `)`. – Barmar Sep 04 '19 at 16:52
  • @epascarello Even with correct case it's wrong. – Barmar Sep 04 '19 at 16:53

1 Answers1

0

There is no such a metod like

document.getElementsBytype("radio")
Kamil Naja
  • 6,267
  • 6
  • 33
  • 47