Hello I need your help to find a way to save my radio input and print it to the screen so I know that it is saved. I have this HTML:
if (document.getElementById('a1').checked) {
rate_value1 = document.getElementById('a1').value;
document.writeln(rate_value1);
}
if (document.getElementById('a2').checked) {
rate_value2 = document.getElementById('a2').value;
document.writeln(rate_value2);
}
if (document.getElementById('a3').checked) {
rate_value3 = document.getElementById('a3').value;
document.writeln(rate_value3);
}
if (document.getElementById('a4').checked) {
rate_value4 = document.getElementById('a4').value;
document.writeln(rate_value4);
}
if (document.getElementById('a5').checked) {
rate_value5 = document.getElementById('a5').value;
document.writeln(rate_value5);
}
<div class='input-form' id="div1">
<h4 id="myText" contenteditable="true">Customize</h4>
<input type="radio" name="rating" value="5" id="a5" ><label for="5">5</label>
<input type="radio" name="rating" value="4" id="a4" ><label for="4">4</label>
<input type="radio" name="rating" value="3" id="a3" ><label for="3">3</label>
<input type="radio" name="rating" value="2" id="a2" ><label for="2">2</label>
<input type="radio" name="rating" value="1" id="a1" ><label for="1">1</label>
</div>
<button type='button' id='but_add' value='Add new'>Add Rating Nums</button>
Thank you for your time
Try creating another element above your <div> and target it whenever you click a radio button.
<p id="details"></p>
<div>
<input type="radio" name="rating" value="5" id="a5" Onclick="display(this.value)" ><label >5</label>
</div>
In your js:
<script>
function display(x){
document.getElementById('details').innerHTML = x;
}
</script>