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>
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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.