I have here a small script that shows/hides certain DIVs depending on which option is selected in a dropdown.
document.getElementById('inquiry').onchange = function() {
var i = 1;
var myDiv = document.getElementById("inquiry" + i);
while(myDiv) {
myDiv.style.display = 'none';
myDiv = document.getElementById(("inquiry" + ++i));
}
document.getElementById(this.value).style.display = 'block';
}
This script basically just checks which value is selected in the dropdown (i.e. value="inquiry1"), and then changes the CSS of a DIV with an ID that equals the selected value of the dropdown (i.e. id="inquiry1").
But now the higher-ups want to change the dropdown to a group of radiobuttons, with the same functionality (if the radiobutton with value "inquiry1" is selected, the div with id="inquiry1" should also change.
How would I go about adapting above script to fit radiobuttons?
It's important that the script is flexible enough to allow for more options to be added in the future (hence the "+ i" stuff)