I am rendering a HTML form through JS and when the user fills the data and clicks on submit, then I am converting into a JSON. But I am unable to fetch the value of checked radio box. Here's my code for rendering the radio box-
return '<div class="">\
<label class="" for="">Gender</label>\
<div class="">\
<div id="">\
<div class="">\
<label for="" class="radio">Male</label>\
<input id="" type="radio" name = "gender" value="M">\
</div>\
<div class="">\
<label for="" class="radio">Female</label>\
<input id="" type="radio" name = "gender" value="F">\
</div>\
<div class="">\
<label for="" class="radio">Others</label>\
<input id="" type="radio" name = "gender" value="O">\
</div>\
</div>\
</div>\
</div>';
};
Here's my function to convert user filled form to JSON,
var convertIntoJSON = function(elements) {
return [].reduce.call(elements, function(data, element){
data[element.name] = element.value;
return data;
}, {});
};
I am calling the above function, as convertIntoJSON(form.elements)
, where form is my actual form container.
Please tell me how can I access the checked radio button through this, through this code no matter what I select in gender field, I am getting gender as "O" everytime.