I'm working on a computer science project and I was wanting to create some Javascript that allows the user to select 1 of 3 things from one drop down menu and another 1 of 3 things from another. The choices are Homeless Shelter, Food Bank, and Salvation Army. Followed by Duncan, Nanaimo, and Victoria. If the user were to pick Homeless Shelter and Duncan, it would present the name and location of the homeless in that town.
I have that part working but it appears that some of my cases are sharing values from my array. For example, every time I change the Array value (say, Relief[6]) in the case that represents Homeless Shelters in Victoria, it also changes Food Banks in Nanaimo. They're sharing cases. I'm guessing that it has something to do with they're drop down values. Homeless Shelter is the third option and Victoria is the first (3 + 1 = 4) and both Nanaimo and Food Banks are second options (2 + 2 = 4)
Here's the entire document:
<!DOCTYPE html>
<HTML>
<HEAD>
<title> Homeless Relief </title>
<script language="Javascript">
"use strict";
var relief = new Array();
relief[0]= "<H3> Homeless Shelter in Duncan </h3><H3> Warmland House </H3> <H3> 371 Festubert St 250-746-5521 </h3>";
relief[1]= "<H3> Food Bank in Duncan </h3><H3> Cowichan Valley Baskey Society </H3> <H3> 5810 Garden St 250-746-1566 </h3>";
relief[2]= "<H3> Salvation Army in Duncan </h3><H3> Community & Family Services - Cowichan Valley Ministries </H3> <H3> 280 Trans Canada Hwy 250-746-8669 </h3>";
relief[3]= "<H3> Homeless Shelter in Nanaimo </h3><H3> Samaritan House </H2> <H3> 355 Nicol St 250-753-1474 </H3>";
relief[4]= "<H3> Food Bank in Nanaimo </h3><H3> Loaves & Fishes Food Bank </H3> <H3> 1009 Farquhar St 250-754-8347 </H3>";
relief[5]= "<H3> Salvation Army in Nanaimo </h3><H3> Nanaimo Community Church </H2> <H3> 505 Eighth St 250-753-8834 </H3>";
relief[6]= "<H3> Homeless Shelter in Victoria </h3><H3> Rock Bay Landing </H3> <H3> 525 Ellice St 250-383-1951 </h3>" ;
relief[7]= "<H3> Food Bank in Victoria </h3><H3> The Mustard Seed </H3> <H3> 625 Queens Ave 250-953-1575 </H3>";
relief[8]= "<H3> Salvation Army in Victoria </h3><H3> The Salvation Army Stan Hagen Centre for Families </H3> <H3> 2695 Quadra St 250-386-8521 </H3>";
function getRelief( )
{
var location = parseFloat(document.reliefform.shelter.value);
var place = parseFloat(document.reliefform.area.value);
var together = location + place;
switch(together)
{
case 0:
document.getElementById("info").innerHTML = relief[0];
break;
case 1:
document.getElementById("info").innerHTML = relief[0];
break;
case 2:
document.getElementById("info").innerHTML = relief[0];
break;
case 3:
document.getElementById("info").innerHTML = relief[0];
break;
case 4:
document.getElementById("info").innerHTML = relief[0];
break;
case 5:
document.getElementById("info").innerHTML = relief[0];
break;
case 6:
document.getElementById("info").innerHTML = relief[0];
break;
case 7:
document.getElementById("info").innerHTML = relief[0];
break;
case 8:
document.getElementById("info").innerHTML = relief[0];
break;
}
}
</script>
</head>
<body>
<H1> Where can I find places of homeless relief in Duncan, Nanaimo, and Victoria? </H1>
<FORM NAME="reliefform">
<select name="shelter">
<option value="1" selected>Homeless Shelter</option>
<option value="2">Food Bank</option>
<option value="3">Salvation Army</option>
</select>
<select name="area">
<option value="1" selected>Duncan</option>
<option value="2">Nanaimo</option>
<option value="3">Victoria</option>
</select>
<input type="button" value="Location" name="selector" onclick="getRelief()">
</form>
<p id="info"> </p>
</body>
</html>
Can anyone explain and show me how to fix this?
reliefstore?