I am trying to make a store locator and I am having problems with the drop down menu, I wanted a drop down menu for the distance from the user to the shops so for example 1 mile 3 miles 10 miles and so on but I can't get a drop down menu to run a function that will show these locations I have tried a couple example I have seen on here for example
Calling javascript functions from drop down
But I can't get it to work for my code the code I am trying to run is:
function list() {
document.getElementById("myList").onchange = function() {
var sheet=document.getElementById("myList").value;
if(sheet == "one"){
showPosition();
}
else if(sheet == "two"){
showPosition2();
}
else if(sheet = "three"){
}
else{
}
return false
};
}
window.onload = list;
The function that I want it to run when I choose the first option in the menu is:
function showPosition(position) {
var locations = [
['store1', -2.063150, 52.516503, 4],
['store2', -2.064824, 52.518436, 5],
['store3', -2.068214, 52.519898, 3],
['store4', -2.068558, 52.512769, 2],
['store5', -2.070875, 52.510758, 1]
];
var lon1 = position.coords.longitude* 0.0174532925;
var lat1 = position.coords.latitude * 0.0174532925;
var i = 0;
while (i < locations.length)
{
x.innerHTML+= "<br>Distance " + calcDist(lon1, lat1, locations[i][1]*0.0174532925, locations[i][2]* 0.0174532925);
i++;
}
}
function calcDist(lon1, lat1, lon2, lat2)
{
return Math.acos(Math.sin(lat1)*Math.sin(lat2) +
Math.cos(lat1)*Math.cos(lat2) *
Math.cos(lon2-lon1)) * 3958;
}
And the menu that I'm using is:
<ul id="dropdown">
<li> Choose theme
<ul>
<li id="stylesheet1" > <a href="#"> Default </a></li>
<li id="stylesheet2" > <a href="#"> Theme 1 </a></li>
<li id="stylesheet3" > <a href="#"> Theme 2 </a></li>
<li id="stylesheet4" > <a href="#"> Theme 3 </a></li>
</ul>
</li>
</ul>