The Boostrap Datepicker fails to display

I'm having trouble integrating a Bootstrap Datepicker into my form. I got it working outside of the form, but when I try to include the code in my form, it doesn't seem to work. All necessary files are present and the code is identical.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>AR_welcome</title>
  <!-- Bootstrap -->
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="/assets/bootstrap/js/bootstrap.min.js">
  </script>
  <link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.min.css" />
  <!-- Font + Style + Icons-->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro">
  <link rel="stylesheet" href="/assets/css/styles.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
  <!-- jQuery -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <!-- Datepicker -->
  <script src="/assets/bootstrap-datepicker/js/bootstrap-datepicker.min.js">
  </script>
  <script src="/assets/bootstrap-datepicker/locales/bootstrap-datepicker.nl.min.js">
  </script>
  <link rel="stylesheet" href="/assets/bootstrap-datepicker/css/bootstrap-datepicker.css">
</head>

<body>
  <script>
    $(document).ready(function() {
      $('.datepicker').datepicker({
        format: "dd-mm-yyyy",
        todayHighlight: true,
        autoclose: true,
        language: 'nl',
        weekStart: '1',
      });
    });
  </script>
  <main>
    <div class="content">
      <form>
        <div class="form-row" style="margin-top:10px;">
          <div class="col">
            <div class="form-group"><label><strong>Pickup date:</strong></label>
              <div id="datepicker-group" class="input-group date"><input class="form-control" name="data" type="text" placeholder="Pickup" /><span class="input-group-addon"><i class="fas fa-calendar-alt"></i></span></div>
            </div>
          </div>
          <div class="col">
            <div class="form-group"><label><strong>Deliver date:</strong></label>
              <div id="datepicker-group" style="display:inline" class="input-group date"><input class="form-control-datepicker" name="data" type="text" placeholder="Deliver" /><span class="input-group-addon"><i class="fas fa-calendar-alt"></i></span>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </main>
</body>

</html>

Is it not possible to use this datepicker within a form? Or could there be another issue with this code?

Answer №1

There seems to be a problem with your HTML:

  1. You have more than one element with the same identifier id="datepicker-group". It should be changed to a class instead.

    <div class="col">
        <div class="form-group">
            <div class="datepicker-group input-group date">
    
            </div>
        </div>
    </div>
    <div class="col">
        <div class="form-group">
            <div class="datepicker-group input-group date">
    
            </div>
        </div>
    </div>
    
  2. In your JavaScript code, you are initializing the datepicker with class .datepicker, but there is no element in your HTML with that class.

    <input class="datepicker" name="data" type="text" placeholder="Deliver" />
    
  3. As per @louys' comment, it appears that some of your libraries are not being loaded in the correct order. Make sure to load jQuery first.

Check out the fiddle here: http://jsfiddle.net/aq9Laaew/171701/

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

Dynamically load content onto a jQuery Mobile page upon clicking a link

I'm relatively new to working with jQuery Mobile and making AJAX requests. Let me try to explain my issue clearly. Currently, I am developing a mobile project and utilizing the jQuery Mobile auto-complete list, populating it with data from an XML fil ...

The Twitter widget is not staying in sync with the rest of the page when scrolling on

Twitter provides a widget that is widely used by many people. Below is the code provided by Twitter: <script src="http://widgets.twimg.com/j/2/widget.js"></script> <script> new TWTR.Widget({ version: 2, type: 'profile', ...

Bootstrap 5's h-100 feature functions flawlessly in Chrome, however, it encounters issues when used with a group

Can you please refer to this question: Issue with Aspect Ratio of Images in Bootstrap 5 due to Padding After applying the h-100 solution, everything looks great on Chrome. Unfortunately, when I check it in Safari, the aspect ratio of the image gets distor ...

Remove 'File' option from the Menu in Tiny MCE

Is there a way to selectively remove the "File" option from the Menu Bar without specifying each individual menu item? https://i.sstatic.net/SFgvi.png I attempted the following method: menu: { edit: {title: 'Edit', items: 'undo redo | cut ...

Uncaught jQuery onchange event not firing

I am facing an issue with a drop-down list inside a data grid on the main page. When values are changed, a popup should display and the values from the popup need to be sent back to the main page. However, I am having trouble triggering the onchange event. ...

Should I reload the entire table or insert a row manually?

This unique ajax question arises: within a table lies the users' information, displayed based on individual settings and timing. Sometimes, users instantly see the data, other times they must wait for it - their choice determines when it appears. Wha ...

Why is the PHP response always 0 even though AJAX JSON data is being sent correctly during Wordpress plugin development?

There seems to be a simple issue here that I'm missing. The data is being sent correctly according to Firebug in the NET tab (NET tab-> Post -> Parameters). However, the PHP function does not even echo simple text. This is the PHP code: add_ac ...

Functionless Ajax post request

Having a bit of trouble with a simple problem and I can't seem to spot the error. Would appreciate any help or insights you might have. Here's the issue at hand: $http({ url:'api/create_plane.php', method: "POST", data: { ...

What is the process for creating this image using HTML and CSS?

Looking to style an image using HTML and CSS. This is what I attempted: <span>$</span><span style="font-size: 50px;">99</span><span style="vertical-align: text-top;">00</span> However, the result doesn't ma ...

Send user input to a Controller method using Ajax

I am working on a MVC3 page that includes a link (Ajax.ActionLink). When the user clicks this link, it triggers a controller action and the result is displayed in a div, replacing the existing content. Here is the code snippet: @Ajax.ImageActionLink("/Im ...

One jQuery plugin was functioning perfectly, while the other one was failing to work as expected

I am working on a simple HTML file that includes a heading and two empty div elements. <h1>Blablabla.</h1> <div id="div1"></div> <div id="div2"></div> These two divs need to be populated with SVG content generated usin ...

Converting Ajax to JSON with Jquery offline and Manifest for enhanced offline web applications

Looking to create an offline web application, I'm in the process of transitioning from Ajax to JSON using JQuery offline. Here is the initial Ajax code: $.ajax({ url: contentpage, data: contentpagedata, cache: false }).done(function( html ) { ...

The listbox is experiencing display issues when viewed in the Chrome browser

Hey, I'm having an issue with adding background color and border to my Listbox. There seems to be a white strip on the right and bottom of the options. The layout rearranges properly when hovering over each item. <select> <option>H ...

Tips for avoiding identical selections in multiple drop-down menus within a table and sending the data to the server via a POST request

For instance: visualizing a chart of infants, where each row the user chooses baby GenderDropDown, then picks a name. It's crucial to prevent duplicate name selections throughout the chart. If a user selects Male & John, that choice should not be ...

The function $.ajax may not be available, but rest assured that the jquery library is functioning properly

Upon checking the console, I noticed the following: Here is the AJAX code snippet in use: $("#accept").click(function(){ id = $("#idInput").val(); password = $("#passwordInput").val(); alert(id) alert(password) $.aja ...

Form-check radio buttons within the form-check-inline class of Bootstrap 4.1.1

I am attempting to showcase a radio button as an inline option. According to the Bootstrap 4.1.1 documentation, the example code is: <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="inlineRadioOption ...

jquery selector to target an element nested inside an anchor tag

Is there a way to use a Jquery selector to extract the text content within the 'name' attribute? <a href="page1.php" id='title' name="<?php echo $res['id'];?>" title="<?php echo $res['title'];?>" < ...

What is the best way to adjust the width of these elements for a perfect fit?

I'm currently working on a website where I have arranged squares in a grid layout. My goal is to make these squares perfect, with equal width and height. The only issue I'm encountering is that they tend to change between fitting two and three sq ...

Obtain Python script output displayed in HTML format

I am currently working on developing Python scripts that can be utilized by front-end HTML+CSS developers for websites. To test the feasibility of this approach, I have written a basic script that makes use of parse.com as the backend. The script retrieves ...

Harvest information from various files

I have a collection of 278 Html files containing essays written by various students. Each file includes the student's ID, first name, and last name in this format: <p>Student ID: 000000</p> <p>First Name: John</p> <p>Las ...