I have radio buttons with the same name and same id, Which are dynamic data, I want to show these radio buttons values in input but when I am checking radio button only first radio button value is showing in input even if I check on second radio or third radio button.
I have three input type radio with the same name and same id but with different values, I am checking second and third radio button but it is showing only first radio button value in input.
<!DOCTYPE html>
<html>
<body>
<input type="radio" name="colors" onclick="myFunction()" value="red" id="myRadio">Red color
<input type="radio" name="colors" onclick="myFunction()" value="blue" id="myRadio">Blue color
<input type="radio" name="colors" onclick="myFunction()" value="green" id="myRadio">Green color
<input type="text" id="demo">
<script>
function myFunction() {
var x = document.getElementById("myRadio").value;
document.getElementById("demo").value = x;
}
</script>
</body>
</html>
When I check on red color then its value should show on input type with id demo and if I check green or blue then it should show these value in input with id demo.