Question about custom coding on the "next button"

We are having some custom coding done which my coder has asked can you bind the next button behaviour to custom javascript function?

Essentially we have an google maps autocomplete (where the user should select from the dropdown after they start typing) on a location field which populates a hidden lat and long field. A value is then calculated based on the hidden lat and long. We want to force the user to select from the auto complete so making the field just required doesn’t help as the user can type anything in without selecting from the dropdown. We want an error message to appear if the hidden lat & long are not completed when the next button is clicked.

Can you make the Next button conditional on the lat and long field being populated? It would not show until a value is stored for lat and long in that case, and would only show if you already have those values.