модал внутри html форма - PullRequest
       0

модал внутри html форма

0 голосов
/ 17 апреля 2020

Эта форма является простой формой регистрации, но я хочу, чтобы под одним из входов была кнопка, которая запускает модальный режим. Моя проблема в том, что скрипт php запускается и запускает одно и то же действие для обеих кнопок, и, таким образом, перезаписывает / игнорирует модальный javascipt.

<form action="action_page.php" method="post">
<input type="text" name="name" placeholder="Your name..">
<input type="text" name="email" placeholder="Your Email.." >
<button id="myBtn">Email usage</button> <!-- Trigger/Open The Modal -->
<div id="myModal" class="modal"> <!-- The Modal -->
  <div class="modal-content"> <!-- Modal content -->
      <span class="close">&times;</span>
      <p>Some text in the Modal..</p>
  </div>
</div>
<input type="text" name="subject" placeholder="Your dance level..">
<button type="submit" name="Send">Submit</button>

Мне не повезло в поиске целое число rnet для этой конкретной проблемы c. Так что, если бы вы могли помочь мне, дорогая община, было бы здорово. Спасибо!

Ответы [ 2 ]

0 голосов
/ 17 апреля 2020

Благодаря моему другу я понял это. Мне просто нужно сделать

<a href="#" id="myBtn">Email usage</a>

вместо

<button id="myBtn">Email usage</button>

И все работает как нужно.

0 голосов
/ 17 апреля 2020

$(document).ready(function() {
  // Get the modal
  var modal = document.getElementById("myModal");

  // Get the button that opens the modal
  var btn = document.getElementById("btn_sum");

  // Get the <span> element that closes the modal
  var span = document.getElementsByClassName("close")[0];

  // When the user clicks the button, open the modal
  btn.onclick = function() {
    modal.style.display = "block";
      // you wanna set 3000 to 300000 to close after 5 min
  setTimeout(() => {
    modal.style.display = "none";
  }, 3000);
  };

  // When the user clicks on <span> (x), close the modal
  span.onclick = function() {
    modal.style.display = "none";
  };

});
/* Modal Style */

/* Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 20px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: scroll; /* Enable scroll if needed */
  background-color: rgb(0, 0, 0); /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 60%;
  top: 10px;
  height: auto;
}

/* The Close Button */
.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
  <head> 
    <!-- jquery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>    
  </head>
  <body>
    <div class="submit_btn" style="padding:10px;">
      <button class="button" id="btn_sum">
        <span>Submit </span>
      </button>
    </div>
    <div class="modal" id="myModal">
      <!-- Modal content -->
      <div class="modal-content">
        <span class="close">&times;</span>
        <form action="action_page.php" method="post">
        <input type="text" name="name" placeholder="Your name..">
        <input type="text" name="email" placeholder="Your Email.." >
        <button id="myBtn">Email usage</button> <!-- Trigger/Open The Modal -->
        <div id="myModal" class="modal"> <!-- The Modal -->
          <div class="modal-content"> <!-- Modal content -->
              <span class="close">&times;</span>
              <p>Some text in the Modal..</p>
          </div>
        </div>
        <input type="text" name="subject" placeholder="Your dance level..">
        <button type="submit" name="Send">Submit</button>
        </form>
      </div>
    </div>
  </body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...