I have two arrays: one for article names, and the other for url links to each article. I am trying to populate a dropdown list within an infowindow with the article names, linking to each article when selected.
It seems as if the links may have to do with using the onchange
event, and otherwise I am using the "domready" eventListener
to access the <select>
elements' id tag.
Here is the relevant code I have so far, which is not working:
function setDropDownList(mapMarker, names, links)
{
// event listener for dropdown list in the map markers' infowindow
google.maps.event.addListener(mapMarker, "domready", function()
{
var articles = document.getElementById("select");
var nextArticle, nextOption;
for(var i = 0; i < names.length; i++)
{
nextArticle = names[i];
nextOption = new Option(nextArticle);
/* add the new option to the option list
("null" for IE5, "-1" for all other browsers) */
try
{
articles.add(nextOption, -1);
}
catch(e)
{
articles.add(nextOption, null);
}
}
});
} // end of function setDropDownList
Since I am calling the setDropDownList function after the marker is placed, I removed that listener and added one to display the infowindow when the marker is clicked.
DEMO http://jsfiddle.net/yV6xv/10/
It's up to you how to handle the onchange event when a selection is made. Right now, it alerts with a message and a dummy link.
I should add that
map
is global.