How do I get values when radio button is checked?

Anupam Mistry

I have three radio buttons with another input. What I want is when I click on any radio button those another input value should be display in the label tag. I try some code but It's not correct.

function displayRadioValue() {
  var ele = document.getElementsByName('plan');  
    for(i = 0; i < ele.length; i++) {
      if(ele[i].checked)
        document.getElementById("investplan").innerHTML = document.getElementById("planinvest").value;
      }
}
<input type="radio" name="plan" checked onclick="displayRadioValue()" />
<input type="text"value="10" id="planinvest1" class="hidden-plan-type">

<input type="radio" name="plan" onclick="displayRadioValue()" />
<input type="text"value="20" id="planinvest2" class="hidden-plan-type">

<input type="radio" name="plan" onclick="displayRadioValue()" />
<input type="text"value="30" id="planinvest3" class="hidden-plan-type">

<label id="investplan"></label>

Carsten Løvbo Andersen

You can use nextElementSibling like in document.getElementById("investplan").innerHTML = ele[i].nextElementSibling.value;

Demo

function displayRadioValue() {
  var ele = document.getElementsByName('plan');
  for (i = 0; i < ele.length; i++) {
    if (ele[i].checked)
      document.getElementById("investplan").innerHTML = ele[i].nextElementSibling.value;
  }
}
<input type="radio" name="plan" checked onclick="displayRadioValue()" />
<input type="text" value="10" id="planinvest1" class="hidden-plan-type">

<input type="radio" name="plan" onclick="displayRadioValue()" />
<input type="text" value="20" id="planinvest2" class="hidden-plan-type">

<input type="radio" name="plan" onclick="displayRadioValue()" />
<input type="text" value="30" id="planinvest3" class="hidden-plan-type">

<label id="investplan"></label>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I get which radio button is checked from a groupbox?

How do i get the Apple from the span when the radio button is checked? Jquery

How can I get the text of radio button if radio button checked?

How do I get the sum of radio button values in Tkinter?

How do I disable text areas based on what radio button is checked when the page loads?

How can I do it : When checked radio button change input required?

How do I get the checked radio button value using only React?

How to get my radio button already checked when I start the page or click anywhere

How do I check if a radio button is checked using JavaScript?

How do I keep checked radio button on the next page with php?

How do I change the name of a label if a specific radio button is checked?

How to set radio button to checked when i click on list item

How to trigger click event when I apply checked to a radio button?

How can I get the data in the radio button even if it is not checked

How can i keep the radio button checked and get the value

How do I add the values of checked radio buttons to a seperate element

Javascript: How to get the value from a checked radio button when more than one radio button is present

How to use checked radio button values in JavaScript

Get the checked radio button

How do I make it so that when I check one radio button, the other radio button in the same form get unchecked in React?

How to get radio button checked in AngularJS?

How to get the checked value of radio button in database?

How to get checked radio button in list view?

how to get checked radio button value in javascript

How to get the checked radio button in JS?

How do i check if a specific Radio button is checked among the other radio buttons using Javascript?

How do I get the correct radio button selected using MVC RadioButtonFor with float values?

How to Get Parent Radio Group of the checked Radio Button?

In jQuery, how do I get the value of a radio button when they all have the same name?