jeudi 28 juin 2018

Javascript variable in form

I'm creating a process which pulls down a static Google map image using their API.

I have a form which has radio buttons with the following map image options:

 Satellite
 Roadmap
 Hybrid
 Terrain

The radio buttons are in a form - part of which is below:

<summary>Basemap</summary>
<div class="group">
<p>Select a Map Style:</p>
<p>
<label><input type="radio" name="basemapStyle" id="basemapStyle" value="Satellite" checked /> Satellite</label>
<label><input type="radio" name="basemapStyle" id="basemapStyle" value="Roadmap"/> Roadmap</label>
<label><input type="radio" name="basemapStyle" id="basemapStyle" value="Hybrid" /> Hybrid</label>
<label><input type="radio" name="basemapStyle" id="basemapStyle" value="Terrain" /> Terrain</label>
</p>
</div>

I have an underlying javascript document which is called from the html page.

It contains the following code:

var bmStyle = document.getElementById("basemapStyle").value;


    if (bmStyle = "Satellite" ) {       
            var basemapStyle = "&maptype=satellite&scale=4&format=png32&key=xxxx";
            }
        else if (bmStyle = "Roadmap" ) {        
            var basemapStyle = "&maptype=roadmap&scale=4&format=png32&key=xxxx";
            }
        else if (bmStyle = "Hybrid" )  {        
            var basemapStyle = "&maptype=hybrid&scale=4&format=png32&key=xxxx";
            }
        else if (bmStyle = "Terrain" )  {       
            var basemapStyle = "&maptype=terrain&scale=4&format=png32&key=xxxx";
            }       

The page loads successfully and a "basemap" is generated. However, the selected radio button makes no difference and the only first variable in the if else statement seems to get loaded.

I feel there's some logic error in the if else statement but I can't seem to get my head round it.

Aucun commentaire:

Enregistrer un commentaire