I want to select a family of radio box elements of the name "clientName." I can do so using:
var x = document.getElementsByName("gender");
I want to create an event listener, such that if any of the radio buttons are clicked, it logs to the console the ID of the clicked element. I imagine this involves using "this" and an onclick event. So I tried the following, and it does not work:
x.addEventListener("click", myScript);
x.onclick=function(){console.log(this)};
However, this does not seem to do anything. How would I achieve the desired result most elegantly?
[[EDIT: This is clearly not a duplicate of that post. This post does not have the jquery tag selected. I am not interested in Jquery answers.]]