Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:47:50+00:00 2026-06-05T06:47:50+00:00

I have two buttons that popup the same Modal window, but display a different

  • 0

I have two buttons that popup the same Modal window, but display a different tab inside the Modal window. In each tab is a form with a number of inputs. My issue is getting the Focus() on the first form input in either of the two tabs inside the Modal.

This is what I have so far (I have left out some unnecessary code):

CoffeeScript:

# Triggers when a modal tab is shown
$ ->
  $('a[data-toggle="tab"]').bind 'shown', (event) =>
    $(this).closest('input').focus()

    # Further info:
    # event.target = activated tab. alert event.target returns 'http://localhost:3000/#tab-1'
    # event.relatedTarget = previous tab. alert event.target returns 'http://localhost:3000/#tab-2'

HTML:

<a href="#modal" id="tab-1-btn">Tab 1 Button</a>
<a href="#modal" id="tab-2-btn">Tab 2 Button</a>

<div class="modal" id="myModal">

  <div class="modal-body">

    <ul class="nav nav-tabs" id="tabs">
      <li class="active"><a href="#home">Home</a></li>
      <li><a href="#profile">Profile</a></li>
    </ul>

    <div class="tab-content" id="tabs">

      <div id="tab-1" class="tab-pane">
        <form id="tab-1-form">
          <input name="tab-1-input" />
        </form>
      </div>

      <div id="tab-2" class="tab-pane">
        <form id="tab-2-form">
          <input name="tab-2-input" />
        </form>
      </div>

    </div>

  </div>
</div>

References:

  • Modal: http://twitter.github.com/bootstrap/javascript.html#modals
  • Tabs: http://twitter.github.com/bootstrap/javascript.html#tabs

I am open to jQuery or Javascript solutions too, I will convert them to CoffeeScript myself if necessary.

Any help would be greatly appreciated, thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:47:52+00:00Added an answer on June 5, 2026 at 6:47 am

    Below is my final CoffeeScript solution, thanks to mg1075 for the help above:

    # Global variable to store tab info
    inputTarget = ""
    
    # Toggle login & sign up forms and focus cursor to top input on each
    $ ->
      $('#tab-1-btn').click ->
        $('#tabs a[href="#tab-1"]').tab('show')
        inputTarget = "input#tab-1-input"
    
    $ ->
      $('#tab-2-btn').click ->
        $('#tabs a[href="#tab-2"]').tab('show')
        inputTarget = "input#tab-2-input"
    
    # Focus on top input when tab changed
    $ ->
      $('a[data-toggle="tab"]').bind 'shown', (event) =>
        currentTabClass = event.target.className + "input" # = tab-1-input
        $("input#" + currentTabInputID).focus()
    
    # Focus on top input when modal is shown
    $ ->
      $('#myModal').bind 'shown', (event) =>
        $(inputTarget).focus()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two radio buttons on my MVC form that I use to hide
I have a form that has two buttons on it, one yes, one no,
Given that I have a popup, with ID popup and in it two buttons,
I have a menu bar that is rotated slightly. Here are two buttons as
I have a MasterPage that has two image buttons , and two content pages,
I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I have two buttons in my flex app next to each other, ButtonA and
I have two buttons on my MVC form: <input name=submit type=submit id=submit value=Save />
i have a textarea and two buttons like <form name=form1> <textarea name=text1> HTML Codes
I have two projects which run as separate processes, but belong to the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.