paran
paran

Reputation: 199

Modal not opening on href

When I click a href=.... (privilege one), it should open modal, but it is not opening. Though the URL bar is changed to project/index.php#privilege_10

$(document).ready(function() {

  $(window.location.hash).modal('show');

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<a href="#privilege_10" class="btn btn-lg btn-dark">Privilege</a>

<!-- The Modal -->
<div class="modal" id="privilege_10">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Privilege Settings for
          <font color="blue">Name</font>
        </h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        <form method="post" action="/jainvidhya/subdomains/teacher/teacher.php?id=10">
          <span class="float-right">Quiz Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Quiz_Name" id="Privilege_Quiz_Id" value="Y"checked='checked'/></span>
          <br />
          <span class="float-right">Question Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Question_Name" id="Privilege_Question_Id" value="Privilege_Question_Value"checked='checked'/></span>
          <br />
          <span class="float-right">Student Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Student_Name" id="Privilege_Student_Id" value="Y"checked='checked'/></span>
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <input type="submit" class="btn btn-lg btn-info" name="submit" value="Submit">
        </form>
      </div>

    </div>
  </div>
</div>


<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

When I click a href=.... (privilege one), it should open modal, but it is not opening. Though the URL bar is changed to project/index.php#privilege_10

Upvotes: 2

Views: 1908

Answers (3)

pymen
pymen

Reputation: 6549

Short answer: use "a" tag with correct href and data-toggle="modal"

<div class="modal-footer">
  <a class="btn btn-primary" data-toggle="modal" href="http://page.com">Yes</a>
  <a class="btn btn-secondary" data-bs-dismiss="modal">No</a>
</div>

Upvotes: 0

paran
paran

Reputation: 199

With the help of Walks's comment adding data-toggle="modal" data-target="#privilege_10" attributes to a tag solves the issue.

$(document).ready(function() {

  $(window.location.hash).modal('show');

});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<a href="#privilege_10" class="btn btn-lg btn-dark" data-toggle="modal" data-target="#privilege_10">Privilege</a>

<!-- The Modal -->
<div class="modal" id="privilege_10">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Privilege Settings for
          <font color="blue">Name</font>
        </h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        <form method="post" action="/jainvidhya/subdomains/teacher/teacher.php?id=10">
          <span class="float-right">Quiz Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Quiz_Name" id="Privilege_Quiz_Id" value="Y"checked='checked'/></span>
          <br />
          <span class="float-right">Question Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Question_Name" id="Privilege_Question_Id" value="Privilege_Question_Value"checked='checked'/></span>
          <br />
          <span class="float-right">Student Settings&nbsp;&nbsp;
		  <input type="checkbox" name="Privilege_Student_Name" id="Privilege_Student_Id" value="Y"checked='checked'/></span>
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <input type="submit" class="btn btn-lg btn-info" name="submit" value="Submit">
        </form>
      </div>

    </div>
  </div>
</div>


<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

Upvotes: 2

Miquel Las Heras
Miquel Las Heras

Reputation: 760

maybe you are missing the # in the selector:

$(`#${window.location.hash}`).modal('show');

Upvotes: 1

Related Questions