Page with an array of tabs and several pop-up windows (using bootstrap)

I'm attempting to develop a webpage with multiple tabs, each containing a table with buttons that open modals on each row. My code functions properly when only one tab contains a modal. However, when I have 2 or more tabs with modals, the content from both tabs appears on a single page instead of being separated into distinct tabs.

Below is the code snippet:

edit-profile.ejs:

<ul class="nav nav-tabs tabs-left">
     <li class="active"><a href="#edit1" data-toggle="tab">Edit 1</a></li>
     <li><a href="#edit2" data-toggle="tab">Edit 2</a></li>
  </ul>

 <div class="col-xs-9">
                  <div class="tab-content">
                    <div class="tab-pane active" id="edit1">
                      <div id="edit1">
                        <% include ./partials/edit-profile/_edit1%>
                      </div>
                    </div>
                    <div class="tab-pane" id="edit2">
                      <div id="edit2">
                        <% include ./partials/edit-profile/_edit2%>
                      </div>
                    </div>
   <center><button type="submit" class="btn btn-default" data-toggle="modal" data-target=".bd-example-modal-sm">Submit</button></center>

In my _edit1.ejs partial, I have:

<table id="edit1-table" class="table table-striped table-bordered order-table dt-responsive">
  <thead>
    <tr>
      <th>User ID</th>
      <th>Email</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit1-modal"></span> User 1</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbbeb8aeb9fa8bbfaeb8bfe5a8a4a6">[email protected]</a></td>
      <td>Address1</td>
    </tr>

    <tr>
      <td> <span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit1-modal"></span> User 2</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="17626472652557637264633974787a">[email protected]</a></td>
      <td>Address2</td>
    </tr>
  </tbody>
</table>

<div id="edit1-modal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"> Edit 1 </h4>
      </div>
      <div class="modal-body">
          <% include ./_edit1-form %>
      <div class="modal-footer">
        <button type="submit" class="btn btn-default pull-left">Submit</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('#edit1-table').DataTable();
} );
</script>

Similar content exists in _edit2.js:

<table id="edit2-table" class="table table-striped table-bordered order-table dt-responsive">
  <thead>
    <tr>
      <th>User ID</th>
      <th>Email</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit2-modal"></span> User 1</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e792948295d6a793829493c984888a">[email protected]</a></td>
      <td>Address1</td>
    </tr>

    <tr>
      <td> <span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit2-modal"></span>User 2</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ce9eff9eeaedce8f9efe8b2fff3f1">[email protected]</a></td>
      <td>Address2</td>
    </tr>
  </tbody>
</table>

<div id="edit2-modal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"> Edit 2 </h4>
      </div>
      <div class="modal-body">
          <% include ./_edit2-form %>
      <div class="modal-footer">
        <button type="submit" class="btn btn-default pull-left">Submit</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('#edit2-table').DataTable();
} );
</script>

Can anyone provide insight as to why my tables are merging onto the same page when both tabs contain modals, despite having different IDs?

Answer №1

Everything is functioning correctly

<!DOCTYPE html>
<html lang="en-US">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
<ul class="nav nav-tabs tabs-left">
     <li class="active"><a href="#edit-one" data-toggle="tab">Edit 1</a></li>
     <li><a href="#edit-two" data-toggle="tab">Edit 2</a></li>
  </ul>

 <!-- Tab content -->
 <div class="col-xs-9">
                  <!-- Tab panes -->
                  <div class="tab-content">
                    
                   <div class="tab-pane active" id="edit-one">
                      <div id="edit1-container">
                        <table id="edit1-table" class="table table-striped table-bordered order-table dt-responsive">
  <thead>
    <tr>
      <th>User ID</th>
      <th>Email Address</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit1-modal"></span> User 1</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01747264733041756472752f626e6c">[email protected]</a></td>
      <td>Address One</td>
    </tr>

    <tr>
      <td> <span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit1-modal"></span> User 2</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0f091f08483a0e1f090e54191517">[email protected]</a></td>
      <td>Address Two</td>
    </tr>
  </tbody>
</table>


<div id="edit1-modal" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> Edit 1 </h4>
        </div>
        <div class="modal-body">
            <% include ./_edit1-form %>
        <div class="modal-footer">
          <button type="submit" class="btn btn-default pull-left">Submit</button>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

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

                    <div class="tab-pane" id="edit-two">
                      <div id="edit2-container">
                        <table id="edit2-table" class="table table-striped table-bordered order-table dt-responsive">
  <thead>
    <tr>
      <th>User ID</th>
      <th>Email</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit2-modal"></span> User 1</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d686e786f2c5d69786e69337e7270">[email protected]</a></td>
      <td>Address One</td>
    </tr>

    <tr>
      <td> <span class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#edit2-modal"></span> Microsoft</td>
      <td> User 2</td>
      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295c5a4c5b1b695d4c5a5d074a4644">[email protected]</a></td>
      <td>Address Two</td>
    </tr>
  </tbody>
</table>;

<div id="edit2-modal" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> Edit 2 </h4>
        </div>
        <div class="modal-body">
            <% include ./_edit2-form %>
        <div class="modal-footer">
          <button type="submit" class="btn btn-default pull-left">Submit</button>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>
                      </div>
                    </div>
               </div>
</div>
   <center>
<button type="submit" class="btn btn-default" data-toggle="modal" data-target=".bd-example-modal-sm">Submit</button>
</center>


  
</div>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to add Internet Explorer specific stylesheets to the Wordpress functions directory using enqueue?

I'm facing challenges setting up my Wordpress theme to be compatible with early versions of Internet Explorer. Most online tutorials have advised me to enqueue specific I.E stylesheets in the header, but this method has not been successful for me. Add ...

Transform the checkbox selection into an active hyperlink upon being selected

Currently, I am in the process of designing a form that allows visitors to select items they would like to view by checking relevant checkboxes. Upon clicking a Request button, the URLs of the selected items are displayed. I aim to have the URL appear as ...

What is the best way to access a JavaScript array within a server-side button click function?

My jQuery code looks like this: <script> $(document).ready(function () { $('#btnGetIDs').click(function getIDs() { var checkedIds = $(":checkbox:checked").map(function () { return this.id; ...

How can an additional value be sent to the form validation method?

I have created a form group like this: import { checkPasswordStrength } from './validators'; @Component({ .... export class PasswordComponent { ... this.userFormPassword = this.fb.group({ 'password': ['', [ ...

Exciting CSS3 animation when hovering over Icon Font and Text

Why is the CSS3 Transition not working on the hover effect for both the text and the coffee cup, and why is there a white border at the bottom of the coffee cup? I am looking to remove the border at the bottom of the cup. The entire thing utilizes the Awe ...

Struggling to delete event listeners in TypeScript using object-oriented programming with JavaScript

After researching the issue, I have discovered that the onMouseUp event is being fired but it is not removing the EventListeners. Many individuals facing a similar problem fail to remove the same function they added initially. Upon reading information fr ...

Looking to adjust the fill pattern dynamically

I previously implemented this code: Is there a way to modify the fill image on my 3 buttons to display in 3 distinct colors instead? ...

What steps do I need to take in Bootstrap 5 to add a search icon to the navbar that reveals a search box beneath it when clicked?

I've made progress on the navbar design Now, I'm looking to add a search icon next to the login button. Clicking on the search icon should reveal a search box below the navbar, similar to the image shown below. My transparent navbar has a relati ...

Footer displaying strange behavior

I am working on creating a static web page within a larger Laravel project. Everything is functioning properly except for the footer which is displaying unusually. Despite being positioned at the bottom of the HTML structure, it is taking up more space and ...

Sequential processing and asynchronous JavaScript

My import script runs recursively before a PHP timeout to process data efficiently. I know that an ajax call responds to a 200 status. Is there a way for success to be triggered only when the script has completed its execution? ...

Configuring unique capabilities for the Selenium WebDriver

My goal is to customize the settings of a Selenium Webdriver. In this particular case, I am looking to modify a capability of the webdriver specifically for the Firefox browser. All of this needs to be done using Javascript. this.driver = new selenium.Bu ...

Survey with results routing based on rating

I am looking to incorporate a basic survey on my website featuring a few multiple choice questions. Each question will be assigned a score, and upon completing the survey, users will be redirected to a personalized page based on their overall score. Doe ...

Utilizing Filters to Dynamically Highlight and Unhighlight HTML in Angular

Currently, I am experimenting with creating a series of filters that can dynamically highlight and remove highlighting from generated HTML: Highlight filter: app.filter('highlight', function ($sce) { return function (str, termsToHighlight) ...

Tips for selecting elements within the overflow container that are hidden:scroll

Is it feasible to fetch all elements located within the "hidden area" of a parent element that has an overflow:scroll property? A parent container, <div>, has a style of overflow:scroll;height:200px. Within this container is a table. Take a look at ...

Decoding GeoJSON: Extracting a feature from an array

I am currently working on a map project where I am drawing polygons with properties pulled from a JSON file. Each polygon is colored based on feature values in the JSON file. Here's an example of a feature in the JSON file: { "type": "Feature", " ...

Using the '&' character in an AJAX request parameter: A step-by-step guide

When passing form data to PHP using jQuery, the PHP code saves the data to a MySQL database. However, if the title is "how to save & to mysql database using PHP", it gets stored in the database as "how to save". How can I resolve this issue? Below is my J ...

Tips for swapping images as a webpage is scrolled [using HTML and JavaScript]

Hi there, I am looking to make some changes to a JavaScript code that will switch out a fixed image depending on the user's scrolling behavior. For example, when the page loads, the image should be displayed on the right side. As the user scrolls down ...

Background images are not appearing in Rails production environment

There seems to be an issue with my images not showing up in the production environment (link here). Here is a snippet of my code: _header.html.erb <%if action_name == 'index' %> <div class="main_header_bg" id="main_head ...

What is the best way to set up a HTML redirect page with Google Analytics code inserted into it?

Is it possible to generate an HTML page that redirects to a subfolder, yet maintains the Google Analytics code block for tracking on the homepage? ...

Click event in jQuery to change the background color of <td> element

I'm still getting the hang of jQuery, so please bear with me. :) The purpose of this code is to color a square with the selected color when clicked if it's white, and turn it back to white if it's already colored. It works fine except for a ...