-3

I need solution That how can i get back checked value of radio button when open a form according to a condition.I got alert value of radiobutton,but no know how tick automatically. If the value =2,Enhancement Give me example in javascript

<input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="1" id="New">New

<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="2" id="Enhancement">Enhancement
</p>

<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="3" id="Fix">Fix
</p>
adiga
  • 34,372
  • 9
  • 61
  • 83
  • 1
    Does this answer your question? [jQuery checkbox change and click event](https://stackoverflow.com/questions/7031226/jquery-checkbox-change-and-click-event) – deepak thomas Jan 13 '20 at 07:57

2 Answers2

1

You can get radio buttons in javascript using document.querySelectorAll('input[name=ChangeTyperadio]') . Then you need to attach click event on them as shown below. Where you can get the value each time the value is changed.

let radioButtons= document.querySelectorAll('input[name=ChangeTyperadio]');
let resultContainer  = document.querySelector('#result'); document.querySelector('input[name=ChangeTyperadio]');

for(radioButton in radioButtons) {
    radioButtons[radioButton].onclick = function() {
        //you get the result here
        resultContainer.innerText = this.value;
    }
}
<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="2" id="Enhancement">Enhancement
</p>

<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="3" id="Fix">Fix
</p>

<p id="result"></p>
Prateek
  • 834
  • 9
  • 28
0

example:(if i got radiobutton value=2 ,then how can i show it on define radio button ticked)

let radioButtons= document.querySelectorAll('input[name=ChangeTyperadio]');
let resultContainer  = document.querySelector('#result'); document.querySelector('input[name=ChangeTyperadio]');

for(radioButton in radioButtons) {
    radioButtons[radioButton].onclick = function() {
        //you get the result here
        resultContainer.innerText = this.value;
    }
}
<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="2" id="Enhancement">Enhancement
</p>

<p class="checkboxclick" style="margin-left:85px">
  <input style="margin-right:5px" type="radio" name="ChangeTyperadio" value="3" id="Fix">Fix
</p>

<p id="result"></p>