I have a select list that will be filled with date of birth ranges, and each one will have a specific answer that will need returning, I am a beginner with javascript and have managed to get it to wor how I want using an if else statement.
the problem is that this list will need to have 40 entries and subsequently 40 answers, which will lead to one hell of a big if statement.
can anyone suggest a simplified way of coding this.
thanks.
<body>
<select id="DobRange">
<option value="" >Please select a date range</option>
<option value="1" >Dob range 1</option>
<option value="2" >Dob range 2</option>
<option value="3" >Dob range 3</option>
<option value="4" >Dob range 4</option>
</select>
<button onclick="message()">Go</button>
<div id="PassTxt"></div>
<script type="text/javascript">
function message(){
var s = document.getElementById('DobRange');
var DobRange = s.options[s.selectedIndex].value;
if (DobRange == "1"){
document.getElementById("PassTxt").innerHTML = "Answer 1";
}
else if (DobRange == "2"){
document.getElementById("PassTxt").innerHTML = "Answer 2";
}
else if (DobRange == "3"){
document.getElementById("PassTxt").innerHTML = "Answer 3";
}
else if (DobRange == "4"){
document.getElementById("PassTxt").innerHTML = "Answer 4";
}
}
</script>