Generating an interactive Datepicker using Jquery

How can I design a dynamic date picker similar to the image provided below?

I have attempted to create one, but I am looking for a more interactive date picker. Is there a way to achieve the design shown in the image? The current date picker does not meet my requirements for my assignment submission.

NaCH.html


        <!DOCTYPE html>
        <html lang="en">
        <head>
        <meta charset="utf-8">
        <title>Design Challenge</title>

        <!-- Viewport-->
        <meta name="viewport" content="width=device-width" />

        <!-- Favicons
        <link rel="shortcut icon" href="img\favicon.png" type="image/x-icon"> -->

        <!-- Bootstrap-->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

         <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

        <script src="js/date.js"></script>

        <!-- Custom CSS-->
        <link rel="stylesheet" href="css/style.css">

    </head>
    <body>
        <section id="block2">
            <div class="container">
                <div class="well"></div>
            </div>
        </section>
        <section id="nach">
            <div class="container2" style="margin-top:40px">
                <div class="col-md-8 col-md-offset-2">
                  <table class="table">
                      <tr class="header">
                        <td style="padding-left:25px;">Show</td>
                        <td>
                            <select>
                             <option value="" style="display:none;"></option>
                             <option value="0">KYC <span>COMPLETED</span></option>
                             <option value="1">MANDATE <span>SENT</span></option>
                             <option value="2">MANDATE <span>RECEIVED</span></option>
                            </select>
                          </td>
                      </tr>
                      <tr class="body">
                        <td >Sl.no</td>
                        <td style="text-align:left;">Customers</td>
                        <td>KYC COMPLETED</td>
                        <td>MANDATE SEND</td>
                        <td>CLEARED</td>
                        <td>DISAPPROVED</td>
                      </tr>
                      <tr id="calenderdate">
                        <td>01</td>
                        <td style="text-align:left;">Ellen <span>De generes</span></td>
                        <td><input type="text" is-datepicker="1" disabled placeholder="01/02/2016">
                        <img class="checked" src="img/success.png" width="10px" height="10px">
                          </td>
                        <td ><input type="text" is-datepicker="1" disabled placeholder="01/02/2016">
                          <img class="checked" src="img/success.png" width="10px" height="10px">
                          </td>
                        <td class="tick2"><input type="text" id = "datepicker" disabled placeholder="01/02/2016"></td>
                        <td class="wrong"><input type="text" id = "datepicker" disabled placeholder="01/02/2016"></td>
                      </tr>
                      <tr id="calenderdate">
                        <td>02</td>
                        <td style="text-align:left;">De generes</td>
                        <td><input type="text" is-datepicker="1" disabled placeholder="01/02/2016">
                          <img class="checked" src="img/success.png" width="10px" height="10px">
                          </td>
                        <td><input type="text" is-datepicker="1" placeholder="01/02/2016">
                          <img class="checked" src="img/gear.png" width="10px" height="10px">
                          </td>
                        <td class="tick3"><input type = "text" id = "datepicker" disabled placeholder="dd mm yy"></td>
                        <td class="wrong3"><input type = "text" id = "datepicker" disabled placeholder="dd mm yy"></td>
                      </tr>
                  </table>
                </div>
            </div>
        </section>
        <script>
         $( function() {
    $( "#datepicker" ).datepicker();
  } );
        </script>
    </body>
</html>
    

Answer №1

<input type="text" is-datepicker="1" />
<input type="text" is-datepicker="1" />
<input type="text" is-datepicker="1" />
<input type="text" is-datepicker="1" />

$(function() { 
  $("[is-datepicker=1]").each(function() {
    $(this).datepicker({
      showOn:"button",
      buttonImage: "img/calendar.png", 
      buttonImageOnly: true 
    }); 
  });
});

In the code above, we are utilizing the attribute is-datepicker for the input fields and instructing the JavaScript to implement the datepicker function on each of these elements.

Answer №2

When dealing with multiple dates, assign unique ids like datepicker1, datepicker2, and so on.

$( "#datepicker1" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
    });

$( "#datepicker2" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
    });

An alternative approach is to use a foreach loop as recommended by Roc Khalil

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

Encountering XMLHttpRequest errors when trying to make an AJAX POST request

I'm encountering an issue with a modal containing a form for submitting emails. Despite setting up the ajax post as usual, the submission is failing consistently. The console displays the following two errors: Setting XMLHttpRequest.withCredent ...

How to position two Bootstrap 4 Navbars side by side

I'm currently experiencing an alignment issue with two stacked navbars in my code. I want to align the upper navbar with the lower one, but I've tried various approaches without much success. Is there a problem with the buttons or something else ...

What is the reason for the unique behavior of v-bind with boolean attributes? More specifically, why is the number 0 considered truthy in

According to the official documentation, <button v-bind:disabled="isButtonDisabled">Button</button> In this example, the disabled attribute will be added if isButtonDisabled is equal to 0, despite the fact that in JavaScript, 0 is co ...

What might be the reason for jQuery not functioning in Internet Explorer 11?

Working on developing a slideout menu for my website using jQuery. It functions perfectly in Chrome, but encountering issues in Internet Explorer (IE11). Extensive search hasn't provided a solution yet. Seeking assistance and any help would be highly ...

Capture a screenshot of an element in either jpg or png format and proceed to save it to your device using Javascript

I am looking to create a JavaScript function that can capture a screenshot of an element and then allow the user to download it. <body> <h1>Sample text</h1> <h2>Sample text</h2> <table width="1080px" height=" ...

Sanitize input data prior to using express-validator in a Node.js application

In my Node.js project, I am utilizing the V4 syntax of express-validator as recommended: const { check, validationResult } = require('express-validator/check'); const { matchedData } = require('express-validator/filter'); Additionally ...

Retrieve a JSON object from a JSON array using a specific key

I am facing a situation where I have a json array containing multiple json objects. Let's take the example of a course object with the following structure: {"name": "Math", "unit": "3"} The json array looks something like this: [{"name": "Math", "u ...

When the back button is pressed on android, the navbar does not immediately refresh the active class

When using a webapp on Chrome for Android, pressing the back button results in double active items in the navbar. Clicking outside of the navbar removes the old active item. I attempted to resolve the issue by adding [routerLinkActiveOptions]="{ exact: tr ...

Stopping a file transfer in case of browser closure or upload cancellation

When working on uploading a file asynchronously using HTML5 in MVC3, a common issue arises when dealing with large files such as 1GB. If the upload process is cancelled or the browser is closed at 50% completion, a 500MB file still gets saved in the target ...

Explore and target elements using browser inspection

Is it possible to create a new CSS class using browser inspection that contains new hover/focus styles? For example: .CanIDo { /*some css rules (ex.)*/ width: 100; } /*my question (USING BROWSER INSPECTOR, not directly typing in the CSS file)*/ .CanI ...

What measures can be taken to avoid the entire page from reloading?

Within my page, there exist two containers. The first container is designated for displaying a list of items, while the second container showcases actions corresponding to each item. A feature allows me to add a new item dynamically to the first container ...

The syntax in JavaScript of (0, fn)(args) is used to call

I came across an interesting piece of JavaScript code in Google's codebase that I wanted to discuss: var myVar = function...; (0, myVar)(args); Do you know what the significance of this syntax is? I'm struggling to see the difference between ( ...

Unable to select checkbox within a table using Selenium WebDriver with Java

Having trouble checking a checkbox inside a table using Selenium Webdriver in Java? Even with version 2.52.0 of Selenium, the element not found error persists across different web browsers. The iFrame seems to be correct as I can interact with other compon ...

Switch classes while navigating within a div

My website has a sticky sidebar with a list of cars and their corresponding categories in a table: <ul class = "cars"> <li class=""><a href="javascript:void(0)" class="model" data-id="1"> BMW </a></li> ...... ...

Python's Selenium encountering a NoSuchElementException with the error message "./ancestor-or-self::form"

Trying to create a Python script that allows me to input my credentials and tweet text in the Python console. The script should then log in and post a tweet using Selenium. Everything works fine, except for the final click on the Tweet button which is caus ...

Ways to transmit data from autocorrect to a higher-level class

Previously, I raised a question about passing state for React via props on Stack Overflow: Laggy TextField Updates in React. I have now revamped my code using ChrisG's approach, where I store states in the parent component FormSection and pass them a ...

How can I target only one mapped item when using onClick in React/NextJS?

Apologies if this question is repetitive, but I couldn't find a better way to phrase my issue. The code in question is as follows: const [isFlipped, setFlipped] = useState(false); const flip = () => { if (!isFlipped) { setFlipped(tr ...

I am looking to showcase images beside individuals' names or photos on my website in a vertical arrangement, similar to how it is done on Facebook

Looking for suggestions on how to display images uploaded by users on my webpage in a way similar to Facebook, with the user's photo displayed beside each image. Any recommendations or website links would be greatly appreciated. Thanks, Santosh Sahu ...

What is the best way to include multiple tags (specifically for articles) in the Facebook Open Graph?

When it comes to a single blog or article with multiple tags, how can you add Facebook Open Graph data? This method seems like the most logical way to do it. However, the Facebook debugger reports that it's incorrect: <meta property = "article: ...

Discover the best way to integrate your checkbox with your Jquery capabilities!

I am having trouble getting my 3 checkboxes to interact with the JQuery button I created. The goal is for the user to be able to select an option, and when the button is clicked, the selected options should download as a CSV file from my feeds. Below is th ...