I'm very new here, any help would be appreciated.
I’m trying to make a contact form which has 5 radio buttons, each radio button has its own div. Inside the div there's a textarea. When radio button 1 is checked, it shows the div, when radio button 2 is checked, it shows the div, but hides the div checked in radio button 1.
Checked radio buttons don't have to be in sequence, they just have to hide the other divs and show the div that is controlled in the currently radio button selected.
I’ve got it as far as when the radio button is checked it shows the div, but it does not hide the div when you select another radio button (all the divs remain shown when you check the radio buttons).
Below the code:
function radioCheck(radio) {
data = radio.getAttribute("data")
switch (data) {
case '1':
document.getElementById('ifRadio'+data).style.display = 'block';
break;
case '2':
document.getElementById('ifRadio'+data).style.display = 'block';
break;
case '3':
document.getElementById('ifRadio'+data).style.display = 'block';
break;
case '4':
document.getElementById('ifRadio'+data).style.display = 'block';
break;
case '5':
document.getElementById('ifRadio'+data).style.display = 'block';
break;
default:
document.getElementById('ifRadio1').style.display = 'none';
}
}
<!--Radio buttons-->
<div class="col-md-6">
<label class="radio-inline">1
<input type="radio" onclick="javascript:radioCheck(this);" data=1 name="fid_7" id="showCheck1"></label>
<label class="radio-inline">2
<input type="radio" onclick="javascript:radioCheck(this);" data=2 name="fid_7" id="showCheck2"></label>
<label class="radio-inline">3
<input type="radio" onclick="javascript:radioCheck(this);" data=3 name="fid_7" id="showCheck3"></label>
<label class="radio-inline">4
<input type="radio" onclick="javascript:radioCheck(this);" data=4 name="fid_7" id="showCheck4"></label>
<label class="radio-inline">5
<input type="radio" onclick="javascript:radioCheck(this);" data=5 name="fid_7" id="showCheck5"></label>
</div>
<!--If radio 1-->
<div id="ifRadio1" style="display:none">
Why did you rate us that way? <br><textarea type="text" id='Radio1' name='yes'></textarea><br>
What’s not working well?<br> <textarea class="form-control" type="text"></textarea>
</div>
<!--If radio 2-->
<div id="ifRadio2" style="display:none">
Why did you rate us that way? <br><textarea class="form-control" type="text" id='Radio2' name='yes'></textarea><br>
What’s not working well?<br> <textarea class="form-control" type="text"></textarea>
</div>
<!--If radio 3-->
<div id="ifRadio3" style="display:none">
Why did you rate us that way? <br><textarea class="form-control" type="text" id='Radio3' name='yes'></textarea><br>
How better can we suit your needs? <br><textarea class="form-control" type="text"></textarea>
</div>
<!--If radio 4-->
<div id="ifRadio4" style="display:none">
Why did you rate us that way? <br><textarea class="form-control" type="text" id='ifRadio4' name='yes'></textarea><br>
Do our timing works for you? <br><textarea class="form-control" type="text"></textarea>
</div>
<!--If radio 5-->
<div id="ifRadio5" style="display:none">
Why did you rate us that way? <br><textarea class="form-control" type="text" id='ifRadio4' name='yes'></textarea><br>
Do our timing works for you? <br><textarea class="form-control" type="text"></textarea>
</div>