views:

492

answers:

1

Hi, it is a quick question that I was hoping someone with a bit more Javascript experience than myself could help me nut out. Basically I am writing a simple HTML form that uses a google map, but to reduce the ammount of clutter on the screen I have removed the google interface and replaced it with some simple submit buttons to change the map type (eg Satellite, Hybrid and Normal). The problem that I am having is that IE refuses to accept the: map.setMapType(G_SATELLITE_MAP);

What is confusing me though, is the fact that my application works beautifally in Safari and FF, yet refuses to work at all in IE8.

Just for reference here is the function I am calling:

function map_type_sat()
{
    map.setMapType(G_SATELLITE_MAP);
    return true;
}

and here is how I am calling it:

<form action ="#" onsubmit="return map_type_sat()">
<input type="Submit"  value="satellite"> 
</form>

can anyone see any issues that would be causing it to not work, or is it an issue with my version of IE having a required plugin to run this command.

Any Help would be greatly appreciated

+1  A: 

I'm not sure why you are using a form submission to set the map type. This may, in fact, be handled differently in IE, potentially causing a full post back even with the '#' target action. Try changing it to use a click handler for a regular input button and omit the form. Note that this also eliminates the need to return a value from the function.

function map_type_sat()
{
    map.setMapType(G_SATELLITE_MAP);
}

<input type='button' value='satellite' onclick='map_type_sat()' />

Or, even better,

function set_map_type( type )
{
    map.setMapType( type );
}

<input type='button' value='normal' onclick='set_map_type(G_NORMAL_MAP);' />
<input type='button' value='satellite' onclick='set_map_type(G_SATELLITE_MAP);' />
<input type='button' value='hybrid' onclick='set_map_type(G_HYBRID_MAP);' />
tvanfosson