Page 1 of 1

using javscript to replace the src of an embeded google map

Posted: Sun May 31, 2009 10:05 pm
by anthony88guy
This is what my embeded google maps code looks like:

Code: Select all

<iframe id="googleMap" width="476" height="345" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&view=map&q=shoreham+verizon+wireless&sll=40.946977,-72.89445&sspn=0.038444,0.090981&gl=us&ie=UTF8&cid=15856891361931225563&ll=40.952029,-72.884502&spn=0.018475,0.036821&z=14&iwloc=A&output=embed"></iframe>
I would like to make a link so that when you click on it, it updates the src in the iframe above. Thus changing the map.

Here is what I have:

Code: Select all

<script type="application/javascript">
function switchDirection(newSrc)
{
    document.getElementById("googleMap").src=newScr;
}
</script>

Code: Select all

<a href="javascript&#058;switchDirection('http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=rocky+point,+ny+to+99+route+25a,+11786&sll=40.941095,-72.920705&sspn=0.023146,0.06609&ie=UTF8&ll=40.941106,-72.92038&spn=0.022692,0.036478&z=14&output=embed');">Rocky Point</a>
Could some please point me in the correct direction.

Re: using javscript to replace the src of an embeded google map

Posted: Sun May 31, 2009 11:25 pm
by mikemike

Code: Select all

document.getElementById("googleMap").src=newScr;
Should be:

Code: Select all

document.getElementById("googleMap").location=newScr;

Re: using javscript to replace the src of an embeded google map

Posted: Mon Jun 01, 2009 10:56 am
by anthony88guy
Why would you set the location property to the "newSrc"? There is no location property... anyway it didn't work.

Re: using javscript to replace the src of an embeded google map

Posted: Mon Jun 01, 2009 2:59 pm
by mikemike
That's what a simple Google search gave me, I tried it in the w3schools editor and it worked fine

Re: using javscript to replace the src of an embeded google map

Posted: Mon Jun 01, 2009 3:03 pm
by anthony88guy
hmm, ill take a look. What did you search for?

Re: using javscript to replace the src of an embeded google map

Posted: Tue Jun 02, 2009 12:20 am
by anthony88guy

Code: Select all

document.getElementById("googleMap").setAttribute("src",newSrc)
is what was needed.

thanks