Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically change google maps script src with select
    primarykey
    data
    text
    <p>I want to change the Google maps script src when one of my dropdown options is clicked because I'm having an issue when searching for zip codes on my page. To get the correct result I believe I need to use Google's Region Localization "&amp;region=" in the src url.(<a href="https://developers.google.com/maps/documentation/javascript/basics#Localization" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/javascript/basics#Localization</a>)</p> <p>I've loaded my google maps api within the <code>&lt;head&gt;</code> tag: </p> <p><code>&lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;</code></p> <p>I've created a drop down list </p> <pre><code>&lt;select id="country"&gt; &lt;option value="sel"&gt;Select&lt;/option&gt; &lt;option value="DK"&gt;Denmark&lt;/option&gt; &lt;option value="NL"&gt;Netherlands&lt;/option&gt; &lt;option value="SE"&gt;Sweden&lt;/option&gt; &lt;/select&gt; </code></pre> <p>I want the google maps script src to change whenever one of the options is clicked on.</p> <p>For example: If I click on Denmark, the src would then change to: <code>http://maps.googleapis.com/maps/api/js?sensor=false&amp;region=DK</code></p> <p>I've tried some stuff out by looking through this <a href="https://stackoverflow.com/questions/8295394/dynamically-change-the-src-of-a-script-tag">Dynamically change the src of a script tag</a> but I still can't figure out how to make it work.</p> <p>At the moment I have this:</p> <pre><code>$('#country option').click(function(e) { e.preventDefault(); var region = $(this).attr('value'); var url = 'http://maps.googleapis.com/maps/api/js?sensor=false&amp;region=' + region; }); </code></pre> <p>I'm really newbie when it comes to jQuery and javascript so I thought maybe I could get some help in here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload