I have created a radio button widget using struts2. I want to retrieve the selected radio button value using javascript function. Please help me. The below code retrieves only the first element.
function getAddress()
{
var add=document.getElementById("add").value;
alert(add);
window.opener.setAddress(add);
window.close();
return true;
}
</script>
<body>
<s:action name="Address" id="addlist"/>
<s:radio label="Address" name="add" list="employeeDetail.addlist">
<br>
</s:radio>
<input type="button" name="nextButton" id="nextButton" value="Select"
onclick="javascript:getAddress();" />
</body>
</html>
you have given the name “add” to the radio element, you need to either replace it with id=”add” or have both – as you are trying to get element by id and it currently has no id.
edit——–
Seeing the rendered HTML it seems that getting the element value by name would be better suited getElementsByName(“add”)