Automatically activate the next tab in Bootstrap

I have a modal that performs a count. Once the count is completed, the modal closes. My goal is to automatically switch to the next tab in Bootstrap when the modal closes.

Here is the HTML:

<ul class="nav nav-tabs namelocationtable">
  <div class="tab-content">
    <li><a data-toggle="tab" href="#one">one></a></li>
    <li><a data-toggle="tab" href="#two">two></a></li>
    <li><a data-toggle="tab" href="#three">three></a></li>
    <div id="one" class="tab-pane fade in active">
      <h1>One</h1>
    </div>
    <div id="two" class="tab-pane fade in">
      <h1>Two</h1>
    </div>
    <div id="three" class="tab-pane fade in">
      <h1>Three</h1>
    </div>
  </div>
</ul>

In tab 1, I trigger the modal to open. Upon closing the modal, I want to automatically switch to tab 2.

Jquery:

// Open the confirmation modal
$("#location-confirm-model").modal('show');

// Timer function and AJAX request
function count_down_timer_function() {
  var sec = 5;
  var timer = setInterval(function() {
      if (sec == 0) {
        clearInterval(timer);
        $("#timer-container").text('Saving details, please wait...');
        $("#location-confirm-model").modal('hide');
        console.log(1);
        $('.namelocationtable > .active').next('li').find('a');
        console.log(2);
        console.log(3);
      }
      $('#timer-container span').text(sec--);
    },
    1000);
  // Cancel countdown and reset text
  $('.cancel-fill').click(function() {
    // Stop the countdown
    clearInterval(timer);
    // Reset timer
    $('#timer-container span').text('5');
  });
  setInterval(timer);
}
count_down_timer_function();

Answer №1

If you're working with Bootstrap 3 (please specify the exact version of Bootstrap), here is a simple script that can help you achieve this functionality:

$('#location-confirm-model').on('hidden.bs.modal', function () {
    $('.nav-tabs a[href="#two"]').tab('show');
})

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

Divide information in the chart

<table id="tab"> <tr><td class="sub">mmmmm</td><td class="sub">jjjjj</td></tr> <tr><td class="sub">lllll</td><td class="sub">wwwww&l ...

Tips for fetching data from a database using AJAX when the values of two drop-down lists are involved

I have successfully implemented an Example where I retrieve data using a single drop-down list from a database. Now, I want to extend this functionality to work with two drop-down lists, where the values retrieved from the database are dependent on the sel ...

My AngularJS ng-show functionality is not functioning as expected. I have already reviewed the syntax and still encountering issues

Having trouble with my ng-show, it's not functioning as expected <div class="form-group"> <label class="control-label col-sm-4">NotesTest:</label> <div class="col-sm-4"> <textarea class="form-control ...

Fastify Schema Failing to Validate Incoming Requests

Currently, our backend setup involves using Node.js and the Fastify framework. We have implemented a schema in satisfy to validate user input. Below is the schema defined in schema.ts: export const profileSchema = { type: 'object', properti ...

Calculating the position of an element in an array passed from a separate file with ReactJS and Ant Design

I'm currently working with a file that contains some JavaScript code featuring an array with multiple objects containing key-value pairs. In my main file (App.jsx), I initialize a State Variable and assign it the array from another JS file. My goal no ...

Element failing to adhere to CSS grid layout

I am currently working with grid layout and aiming to position the following content at the bottom and center, but it is currently aligning to the left: .body { margin: 0; background-color: rgb(255, 237, 237); display: grid; grid-template-rows: ...

Guide on generating a dynamic table by looping through an array and placing values inside <tr> tags, then saving it in a variable

I am working with an array object and need to dynamically create a table where each tablerow (tr) pulls values from the array object. After creating the table, I want to store it in a variable so that I can pass it to a rest call, triggering an email with ...

CSS hover image resizing not functioning as expected

Is there a way to dynamically scale up an image when hovered over? I'm trying to achieve an effect where the image increases from 100x75 pixels to 300x225 pixels. Everything seems to be working fine with the layout, but the width doesn't seem to ...

What is the best way to locate an element with the class name being an email address using jQuery?

Is it possible to locate an element with an email address as the class name, considering that the email address varies? $(document).ready(function(){ //not working getting error var email="<a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

Unlocking the Potential of NextJS with Dynamic Page Export - Say Goodbye to Static HTML!

I am attempting to export my NextJs project based on the official documentation provided. However, it seems that I can only export it into static HTML. Is there a way to export it into dynamic pages where user-submitted data is updated in real time, simil ...

Tips for converting the Instagram cURL post request to a JavaScript request

I am attempting to convert the code I received from Instagram into a token. The code provided in the Instagram DOCS uses a curl request, but I would like to implement it using JavaScript instead. Here is how the original code looks: curl -X POST &bsol ...

Tips on managing multiple form data using ajax for php backend

<input type="text" value="2021-05-01" class="date" name="date"> <input type="text" value="10:00" class="starttime" name="starttime"> ...

Comparison between setTimeout for this.state and useState

When working with a class component, the code looks like this: setTimeout(() => console.log(this.state.count), 5000); Whereas when using hooks: const [count, setCount] = useState(0); setTimeout(() => console.log(count), 5000); If the setTimeout fun ...

Having difficulty aligning the container div in the center

I'm trying to create a centered grid of full-width buttons, but for some reason, I just can't seem to get the container centered. Any suggestions? Check out the code here - https://jsfiddle.net/a6qo6tzL/ Thank you! <div class="Wrapper"> ...

Securing string parameters in Django templates for JavaScript function usage

Can anyone help me with a JavaScript function that is returning a set of objects? return Func("{{id}}", "{{name}}") I'm encountering an issue when passing strings that contain quotes, such as "Dr.Seuss' "ABC""BOOk"", which leads to invalid synt ...

How can we leverage Shared and Core modules alongside Feature modules in Angular development?

When developing my Angular application, I have adopted a specific architecture approach and included a shared.module.ts file in the shared folder. While leveraging lazy-loading in my app, I find myself puzzled about the necessary imports, declarations, and ...

Unable to access an element using jquery

This is an example of an HTML file: <div id ="main"> </div> Here is the JavaScript code: //creating a new div element var divElem = $('<div class="divText"></div>'); //creating an input element inside the div var i ...

In search of a screenplay that mirrors a specific scenario

I recently came across this website: One interesting feature is that all the content loads dynamically on the same page. Instead of loading separate pages, it pauses to fetch the content before smoothly scrolling to the correct section. ...

The appearance of the webkit-scrollbar is not reflecting the intended style

I have successfully created a wrapper for a styled scrollbar in React JS - import styled from '@emotion/styled'; export const ScrollbarWrapper = styled.div(() => ({ maxHeight: '65vh', overflowY: 'auto', '*::-web ...