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

Appearing text dialogue

Can you tell me the name of the box that appears on top of a webpage? A couple of examples include: Facebook photos - It dims the background webpage and opens a separate pop-up to display pictures. Advertisements - The box that typically requires clickin ...

Blend the power of Dynamic classes with data binders in Vue.js

Recently, I've been working on a v-for loop in HTML that looks like this: <ul v-for="(item, index) in openweathermap.list"> <li>{{item.dt_txt}}</li> <li>{{item.weather[0].description}}</li> <li>{{item.w ...

Deciphering the JavaScript code excerpt

This information was sourced from (function ($, undefined) { // more code ... $.getJSON("https://api.github.com/orgs/twitter/members?callback=?", function (result) { var members = result.data; $(function () { $("#num- ...

Using Node.js to Send Parameters in a POST Request

I have a node.js application with an express framework and a POST route defined as follows: app.post('/test', function(req, res){ //res.send(req.body.title + req.body.body) console.log(req.params); console.log(req.body); console.log(req.bod ...

Struggling to make comparisons with numerical data from MongoDB in an ExpressJS route

I am currently developing a website using Node.js, EJS template, MongoDB, and Express. I am working on implementing search functionality on my page using forms, but I am encountering a small issue. The problem is related to a logical issue in the search f ...

Implementing a time delay for submitting an ajax form

I am looking for a way to delay the submission of a form by 2 seconds. I have tried different solutions, but none seem to work for me. I attempted using setTimeout to set a delay, but it is not working as expected. Here is my script and the form tag - wh ...

Create a new build for testing and debugging using create-react-app

Currently, I am in the process of developing a web application that utilizes a React frontend and is powered by a golang api layer. Although I do not have extensive experience with Javascript, I find myself struggling with the Node build system. I am loo ...

Exploring the scope of event listeners in jQuery's TimeCircles

Currently experimenting with the jquery timer known as "TimeCircles", which can be found here. I have successfully set up a minute / second timer for 30 minutes with an alert that triggers at 25 minutes. My goal is to implement an event when the timer hits ...

Ajax in action

I've encountered a problem with my JavaScript function. The function is supposed to display an alert when called without AJAX, but it's not working when I include AJAX. Here's the function: function stopSelected(){ var stop=document ...

Enhance my code to eliminate repetitive elements

Check out this unique plant array: export const uniquePlants = [ { name: 'monstera', category: 'classique', id: '1ed' }, { name: 'ficus lyrata&ap ...

Does WebSVG struggle with producing sharp, defined lines in its inline format?

Upon page load, my SVG background starts as separated and then smoothly transitions into forming the background. However, I noticed that a large triangle with poor quality and choppiness appears at the beginning. What could be causing this issue? For an e ...

Experience the latest HTML5 features directly within a Java desktop GUI, with seamless communication through

This Java desktop GUI utilizes a Java-based web services communication layer along with an HTML library to provide powerful charting and interactivity. I am looking to integrate an HTML5 view within the Java GUI. Can someone assist me in managing JavaScri ...

Issues with local storage ternary expression in React are causing unexpected behavior

I am attempting to accomplish this task. const userToken = localStorage.getItem('token') {userToken.length ? null : <div className='registerLogin'> Register... </div> } The ternary operator is not working ...

Transforming JSON objects, retrieve an empty value in place of undefined

Can someone please offer some advice on the following: I am retrieving JSON data using this code snippet: $.getJSON(jsonPath, function(returnedData){ ... }); The JSON object returned will have a structure similar to this: ... "skin": { "elapsedTextCo ...

Generating a random number to be input into the angular 2 form group index can be done by following these

One interesting feature of my form is the dynamic input field where users can easily add more fields by simply clicking on a button. These input fields are then linked to the template using ngFor, as shown below: *ngFor="let data of getTasks(myFormdata); ...

The .value property on the form group displays numeric values as either null or an empty string

I'm encountering an issue with extracting data from a form group. Within my code, there is a formGroup named lineitemForm, and I am attempting to structure this form group as follows: private formatTransferData() { const depositDates = this.get ...

Eliminating certain buttons within Ember-leaflet-draw

Is there a way to remove specific buttons from the UI in my Ember application that are used for drawing lines, circles, and polygons? I am currently using Leaflet Draw in my project. Here is a snippet of my template.hbs: {{#leaflet-map onLoad=(action &apo ...

Combining these two statements in jQuery: What's the best way to do it?

if($(this).parents("ul").closest("#menu-main").length){ var parent = $(this).parent(); parent.addClass("current"); if(parent.hasClass("more-options")){ $(parent).siblings(".more-options-page").addClass("current").show(); } } Instead of redun ...

Comparable to LINQ SingleOrDefault()

I frequently utilize this particular pattern in my Typescript coding: class Vegetable { constructor(public id: number, public name: string) { } } var vegetableArray = new Array<Vegetable>(); vegetableArray.push(new Vegetable(1, "Carrot")); ...

JavaScript throws an error when attempting to access an object's methods and attributes

Within my Angular.js module, I have defined an object like this: $scope.Stack = function () { this.top = null; this.size = 0; }; However, when I try to use the push method of this object, I encounter an error stating undefined: ...