The modals equipped with data-dismiss="modal" and data-target="#id" do not navigate to their intended destination

Attempting to focus the input field using the modal data-target function on button click. The input field is focused, but a div called

<div class="modal-backdrop in">
is created and the modal does not close properly. This prevents the user from clicking anywhere else on the site. This issue seems undocumented, so hopefully someone here can provide some insight. The goal is to focus on the input field when the user clicks the Upload Now button on the modal. You can view the demo here.

.height500 {
  height:500px;
  background-color:yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="height500"><input type="text" name="" class="" id="noimgtakediv" /></div>
<a data-toggle="modal" data-target="#portfoliomsgmodal" class="btn btn-danger btn-sm"> Click to Open Modal</a>

<!-- Modal -->
<div id="portfoliomsgmodal" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">TIP</h3> </div>
            <div class="modal-body">
                    <label>There are twice as much chances of you getting contacted by your customers if you upload something in your portfolio. Upload photos or video or audio links to your profile.</label>
            </div>
            <div class="modal-footer">
                <button class="btn btn-warning" data-target="#noimgtakediv" data-toggle="modal" data-dismiss="modal">Upload Now</button> 
                <input type="submit" id="submitlater" class="btn btn-primary nomargin" value="Remind me later">
            </div>
        </div>
    </div>
</div>

Answer №1

Take a look at this

.height500 {
  height:500px;
  background-color:yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="height500"><input type="text" name="" class="" id="noimgtakedivnew" /></div>
<a data-toggle="modal" data-target="#portfoliomsgmodal" class="btn btn-danger btn-sm"> Click to Open Modal</a>

<!-- Modal -->
<div id="portfoliomsgmodal" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">TIP</h3> </div>
            <div class="modal-body">
                    <label>Increase your chances of customer contact by adding content to your portfolio. Upload photos, videos, or audio links to attract more attention.</label>
            </div>
            <div class="modal-footer">
                <button class="btn btn-warning" data-toggle="modal" data-dismiss="modal" onclick="focusontest()">Upload Now</button> 
                <input type="submit" id="submitlater" class="btn btn-primary nomargin" value="Remind me later">
            </div>
        </div>
    </div>
</div>

<script>
function focusontest()
{
setTimeout(function(){   $("#noimgtakedivnew").focus() }, 500);
}
</script>

Answer №2

How to utilize Jquery focus() method

$('#portfoliomsgmodal').on('hidden.bs.modal', function (e) {
  $('#noimgtakediv').focus();
})
.height500 {
  height:500px;
  background-color:yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="height500"><input type="text" name="" class="" id="noimgtakediv" /></div>
<a data-toggle="modal" data-target="#portfoliomsgmodal" class="btn btn-danger btn-sm"> Click to Open Modal</a>

<!-- Modal -->
<div id="portfoliomsgmodal" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">TIP</h3> </div>
            <div class="modal-body">
                    <label>There are twice as much chances of you getting contacted by your customers if you upload something in your portfolio. Upload photos or video or audio links to your profile.</label>
            </div>
            <div class="modal-footer">
                <button class="btn btn-warning"  data-toggle="modal" data-dismiss="modal">Upload Now</button> 
                <input type="submit" id="submitlater" class="btn btn-primary nomargin" value="Remind me later">
            </div>
        </div>
    </div>
</div>

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

Exploration of jQuery Dropdown Menus

Encountering a problem with my dropdown menu. Check out the code here: http://jsfiddle.net/xY2p6/1/ It seems like a simple issue that I can't figure out, but as shown in the link, the functionality is not working properly. I need help linking the hid ...

Finding your way to a <div data-role="page"> sans the use of an anchor tag

I need assistance with a specific HTML setup. The first div tag in the code below contains a form with a table that has two columns labeled A and B, along with a button. The second div tag holds a text box, dropdown menu, and submit button. When the button ...

Checking for multiple click events in jQuery

To access the complete code, visit the GitHub Pages link provided below: Link This is how the HTML code appears: <ul class="deck"> <li class="card"> <i class="fa fa-diamond"></i> </li> ...

Why is it possible to apply column width to a div element, but not to a button?

This code functions properly and sets the button to a size 4: <div class="col-xs-4"> <button class="btn btn-block btn-primary">Like</button> </div> However, the following code does not work as expected: <div> <bu ...

Enhance your Shopify experience by utilizing the powerful functionality to manage your cart

I'm facing difficulties when adding or removing items from the cart attributes in Shopify. I've followed the guidance provided in the official documentation and essentially copied and made slight modifications to this code: let formData = { &apo ...

Tips on Including a Custom Header in an Ajax Request for a Cross-Domain JsonP Call

Is there a way to add a custom header using an ajax call in jQuery for a cross-domain JSONP call? I am making a web service call in an HTML page using Ajax cross-domain call. I am currently using JSONP and now need to send some parameters in the header. ...

Applying a unique style to an element using its ID is effective, but using a class does

Incorporating twitter bootstrap tables has been a focus of mine lately, particularly when it comes to custom styling such as setting background colors for table elements. Here's what I've discovered: by assigning id="foo" to each <td> elem ...

What is the best way to target an HTML element that is only connected to a particular class?

My HTML code includes the following 3 elements: <span class="a b"></span> <span class="a"></span> <span class="a b"></span> I am trying to select the element that only has the class "a". When I use $("span.a"), it sele ...

Which Wordpress theme would be best suited for this particular website?

I am looking to create a website on WordPress that resembles the design of this specific webpage: http://www.landrover.co.uk/index.html I need it for commercial purposes. Are there any templates available, either free or paid, with similar features? I do ...

JQuery continuously firing off AJAX requests

Currently, I am experimenting with using a Jquery Ajax request to incorporate an AutoComplete feature. This involves utilizing ElasticSearch on the backend for data retrieval. This is what my autocomplete.html looks like: <!DOCTYPE html> <html l ...

Passing a variable into the highcharts function using jquery and pug is proving to be a challenge for me

I am facing an issue while trying to pass a variable into the Highcharts function using jquery and pug. This variable is essential for setting data in series. In order to tackle this problem, I have created a function called getData in my index.js file whi ...

Is this considered a table?

In the realm of web development, there is a well-known mantra: "Only use tables for tabular data." This advice stems from a time when tables were misused for all sorts of layout purposes. While I generally adhere to this guideline, there are moments when ...

`Error encountered when attempting to convert date with Angular JS filter`

Utilizing angular js filter in the controller for date formatting. A user selects a date from a uib-datepicker-popup. The goal is to format this date using ISO 8601 (yyyy-mm-dd) date format. Upon logging the user-selected date, the output is as follows: S ...

Efficiently scheduling file downloads using WebDriver automation

I am in the process of automating a website using WebDriver, but I have encountered unique file download requirements that differ from what is readily available online. My specific scenario involves a website where I create orders. Upon clicking the &apos ...

What could be causing the Monster model to not appear when using the glTFLoader in three.js on iOS?

-Details- three.js version : r84 (current version) Device : iPad Air2 iOS version : 10.0.2 Browser : Chrome, Safari -glTFLoader- URL : Monster -> NOT visible The rest -> visible Why am I asking this question? I have encountered a similar is ...

Troubleshooting overflow problems when centering a UL menu with an unspecified width

Trying to create a demo where the scrollbars are removed when resizing smaller, but adding overflow: hidden causes issues with sub-menus. Demo Link HTML <nav> <ul> <li><a href="#">Menu Item</a></li> ...

The `chrome.windows` API is not defined for this particular Chrome

I'm currently in the process of developing a Chrome extension that will allow users to effectively manage open tabs within a specific application's website. Here is the current manifest file: { "manifest_version": 2, "name": "AT Tabs", ...

Determine the amount of time that can be allocated based on the attributes contained within the object

I am faced with a JSON structure like the one below: var meetings = [ { id: '1', start_time: "2020-11-15T08:30:00+00:00", end_time: "2020-11-15T14:15:00+00:00" }, { id: '2', start_time: &quo ...

There are three checkboxes, one of which is independent of the others and requires jQuery to not consider it part of the collection

Initially, I crafted a query that perfectly met the business requirement until there was a change of heart. Uncheck checkbox if checked with jquery The implementation of this code was flawless $('input[type="checkbox"]').on('change' ...

Issue with SVG animation causing unnecessary duplication of circle shapes when utilizing animateMotion

I have implemented animateMotion to create an animation along a path. Below is the code snippet that demonstrates this: <!DOCTYPE html> <html> <head> <title>Example Of Many Things!</title> </head> <body> ...