I have the following JavaScript code:
<script type='text/javascipt' language="javascript">
function getUserLoc() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayResult, displayError);
}
else {
setMessage("Geolocation is not supported by this browser");
}
}
function displayResult(position) {
setMessage("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude);
}
function setMessage(msg) {
document.forms[0].myLoc.value = msg;
}
function displayError(error) {
var errors = { 1: 'Permission denied', 2: 'Position unavailable', 3: 'Request timeout' };
setMessage("Error occured: " + errors[error.code]);
}
</script>
As well as this in ASP.NET:
<asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="LoginUserValidationGroup"
OnClientClick="getUserLoc( )" />
However when I click the ‘LoginButton’ I get the JavaScript error: getuserlock is undefined
There’s a typo in your code. You have:
but it should be
(text/javascript)
Also, remove the unnecessary space in your method call because it can give the impression that there’s supposed to be a parameter entered. (This isn’t required, but more of a personal preference)