0

I recently start learning jquery, and php now i want to develop a very simple website and i need to have several modals, although i can copy a modal from here getbootstrap.com and paste it on my index page, it will work, but it would be to hard to find like div or input, that is why i want make a separate page for modals, I did make one here is the modal page + modal.js class and the Index page.

<!-- modal page -->
<!DOCTYPE html>
<html>

<head>
    <title> </title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  
</head>

<body>
   <!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn1" >
    modal 1
</button>

<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal 1</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
<!-- =========================modal 2 -->
</body>

</html>

<!--  Index: page that have the modal button -->
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="./bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="./fontawesome/css/all.min.css">
    <script src="./bootstrap/jquery.min.js"></script>
    <script src="./bootstrap/bootstrap.min.js"></script>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h2>Accordion with symbols</h2>
    <p>In this example we have added a "plus" sign to each button. When the user clicks on the button, the "plus" sign is replaced with a "minus" sign.</p>
    <button class="accordion"><i class="fas fa-address-card"></i></button>
    <div class="panel">
        <div class="container">
            <h2>Basic Table</h2>
            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>insert</th>
                        <th>edit</th>
                        <th>delete</th>
                        <th>view</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>
                            <!-- Button trigger modal -->
                            <button type="button" class="btn btn-primary btn1">
                                modal 1
                            </button>
                        </td>
                        <td>
                            <button type="button" class="btn btn-primary btn1">
                                <i class="fas fa-address-card">
                                </i>
                            </button>
                        </td>
                        <td>
                            <button type="button" class="btn btn-primary btn1">
                                <i class="fas fa-address-card">
                                </i>
                            </button>
                        </td>
                        <td>
                            <button type="button" class="btn btn-primary btn1">
                                <i class="fas fa-address-card">
                                </i>
                            </button>
                        </td>
                    </tr>
                    <tr>
                </tbody>
            </table>
            <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit omnis aspernatur doloremque quidem eos itaque sed earum nesciunt autem. Ullam quod obcaecati, fuga alias totam autem iusto id ratione reprehenderit.</div>
            <div>Totam eum saepe, commodi nemo atque in aperiam nisi tempore! Beatae, sequi aperiam commodi quam distinctio, fugit incidunt officia aliquam, suscipit blanditiis facilis ad vel consectetur temporibus? Soluta placeat, autem?</div>
            <div>Laudantium aperiam veniam, corrupti maiores eligendi nam unde possimus dolorem necessitatibus vitae, velit quam id nobis debitis rerum. Amet non possimus, voluptatem! Consectetur ex, in eos eaque reprehenderit at aliquam.</div>
        </div>
    </div>
    <button class="accordion"><i class="fas fa-address-card"></i>Section 2 </button>
    <div class="panel">
        <div class="container">
            <h2>Basic Table</h2>
            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>insert</th>
                        <th>edit</th>
                        <th>delete</th>
                        <th>view</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                    </tr>
                    <tr>
                </tbody>
            </table>
        </div>
    </div>
    <button class="accordion">Section 3</button>
    <div class="panel">
        <div class="container">
            <h2>Basic Table</h2>
            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>insert</th>
                        <th>edit</th>
                        <th>delete</th>
                        <th>view</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                    </tr>
                    <tr>
                </tbody>
            </table>
        </div>
    </div>
    <button class="accordion">Section 4</button>
    <div class="panel">
        <div class="container">
            <h2>Basic Table</h2>
            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>insert</th>
                        <th>edit</th>
                        <th>delete</th>
                        <th>view</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                    </tr>
                    <tr>
                </tbody>
            </table>
        </div>
    </div>
    <button class="accordion">Section 5</button>
    <div class="panel">
        <div class="container">
            <h2>Basic Table</h2>
            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                        <th>insert</th>
                        <th>edit</th>
                        <th>delete</th>
                        <th>view</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                    </tr>
                    <tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
<script src="modal.js">
</script>

</html>

   $(document).on('click', '.btn1', function(){
    $('#modal1').modal('show');
  });
       
      
Usama Abdulrehman
  • 1,041
  • 3
  • 11
  • 21
Saboor Hamedi
  • 21
  • 1
  • 2
  • 10
  • 3
    I want to clarify what is that you are looking for. You are looking to not have the modal HTML in the HTML of your page, but instead have it loaded from a remote file? – imvain2 May 18 '20 at 20:43
  • Thanks for quick reply, Yes it’s like a remote calling a modal from another page. Like make one page for modal, one for js and another for main and call the modal call and display the modal. – Saboor Hamedi May 18 '20 at 21:13
  • exactly, that is what i want, but it does not work as well – Saboor Hamedi May 18 '20 at 21:43
  • For your remote file, you do not want any extra HTML in it. Just the modal itself, no `head` no `body` nothing besides the modal. – imvain2 May 18 '20 at 21:59
  • I tried that too, but I can't call the modal from another class with jquery. The only goal I have is to retrieve data dynamically to update it, but the modal should be in different page, not on the same page that i have my table. – Saboor Hamedi May 19 '20 at 06:56

0 Answers0