App development on rails
I want to solve the problem that when I press the income button of my current location, the new post button reacts for some reason and posts.

        <button>#Why do you press this button?
              Get the current position
    <% = javascript_pack_tag'photo/new'%>

    <% = f.submit "Post", class:'post-new'%># This button reacts and posts

Contents of<% = javascript_pack_tag'photo/new'%>↓

// Processing when the button is pressed
document.getElementById ("get-position-btn"). onclick = function () {
  // Get location information
  navigator.geolocation.getCurrentPosition (successCallback, errorCallback);
// Processing when acquisition is successful
function successCallback (position) {
  // Get the latitude and display it on the screen
  var latitude = position.coords.latitude;
  document.getElementById ("latitude"). innerHTML = latitude;
  document.getElementById ("latitude-form"). value = latitude;
  // Get the longitude and display it on the screen
  var longitude = position.coords.longitude;
  document.getElementById ("longitude"). innerHTML = longitude;
  document.getElementById ("longitude-form"). value = longitude;
  var latlng = new google.maps.LatLng (latitude, longitude);
  var marker = new google.maps.Marker ({{
    map: map,
    position: latlng
  map.setCenter (latlng);
// Processing when acquisition fails
function errorCallback (error) {
  alert ("Location information could not be obtained");
(function () {
  console.log ("OK");

It's like this
When I clicked, I was able to get the location information, but at the same time, the post button was pressed.
If i know the cause, please answer!

  • Answer # 1

    Because type is not specified for button in form
    It looks like it's functioning as a submit.