I’m having some strange problem with my JS program. I had this working properly but for some reason it’s no longer working. I just want to find the value of the radio button
In case someone was looking for an answer and landed here like me, from Chrome 34 and Firefox 33 you can do the following:
var form = document.theForm;
var radios = form.elements['genderS'];
alert(radios.value);
or simpler:
alert(document.theForm.genderS.value);
refrence: https://developer.mozilla.org/en-US/docs/Web/API/RadioNodeList/value
var value = $('input:radio[name="radiogroupname"]:checked').val();
let genderS = Array.from(document.getElementsByName("genderS")).find(r => r.checked).value;
Edit: As said by Chips_100 you should use :
var sizes = document.theForm[field];
directly without using the test variable.
Old answer:
Shouldn't you eval
like this ?
var sizes = eval(test);
I don't know how that works, but to me you're only copying a string.
Using a pure javascript, you can handle the reference to the object that dispatched the event.
function (event) {
console.log(event.target.value);
}
document.forms.your-form-name.elements.radio-button-name.value