GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

HTMLGeolocationElement: validationstatuschange event

HTML DOM

HTML DOM

The **`validationstatuschange`** event of the HTMLGeolocationElement interface is fired whenever the geolocation element's isValid value changes.

This occurs as a result of a [blocker](/docs/Web/HTML/Reference/Elements/geolocation#geolocation_blocking) being added to or removed from a `<geolocation>` element.

## Syntax

Use the event name in addEventListener():

```js-nolint
addEventListener("validationstatuschange", (event) => { })
```

Alternatively, assign to the [event handler property](/docs/Web/API/Document_Object_Model/Events#using_onevent_properties) of the interface:

```js-nolint
onvalidationstatuschange = (event) => { }
```

## Event type

An Event.

## Examples

### Using `validationstatuschange` to report invalid reasons

In our [Exploring invalid reasons demo](https://mdn.github.io/dom-examples/geolocation-element/exploring-invalid-reasons/) ([source code](https://github.com/mdn/dom-examples/tree/main/geolocation-element/exploring-invalid-reasons)), we use a `validationstatuschange` event handler to report when a `<geolocation>` element becomes valid, and report the invalid reason when it becomes invalid:

```js
geo.addEventListener("validationstatuschange", () => {
if (geo.isValid) {
reasonElem.textContent = `<geolocation> is valid`;
} else {
reasonElem.textContent = `Invalid reason: ${geo.invalidReason}`;
}
});
```

Whenever the validation status changes, we check whether the `<geolocation>` element is valid using HTMLGeolocationElement.isValid, and if so, print a message confirming this to the `<p>` element text content. If the `<geolocation>` element is invalid, we print the HTMLGeolocationElement.invalidReason to the `<p>` element text content.

See the HTMLGeolocationElement.invalidReason page for a full walkthrough of this example.

## Specifications

## Browser compatibility

## See also

- geolocation element

source: MDN Web Docs mirror · page

Cite this

"HTMLGeolocationElement: validationstatuschange event". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/HTMLGeolocationElement/validationstatuschange_event

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·