Generating an interactive Datepicker using Jquery

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

https://i.sstatic.net/euoNI.png

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

Learn the process of assigning a value to a dynamically created textbox using JavaScript in code behind

To create a textbox in the code behind, I use the following method: TextBox txt = new TextBox(); txt.ID = "txtRef" + count + dr["DataField"].ToString(); div.Controls.Add(txt); I have been attempting to set the value for this textbox within a jQuery funct ...

Content refuses to show up on my social networking website project when Ajax is employed

I've been working on a Social Media website for a major project, and I recently implemented Ajax to load posts. However, I'm facing an issue where the content is not displaying on the index page after implementation. My goal is to load 10 posts a ...

Error 107 occurred while attempting to parse JSON data using the AJAX technique with the REST API

I've encountered an issue while attempting to utilize the Parse REST API for sending push notifications. Every time I make an AJAX call, I receive an invalid JSON error in the response and a status code of 400. Below is my request: $.ajax({ url: & ...

Section content neatly framed by a stationary menu overlay

I created a menu structured like this: <div id="menu"> <a href="#p1">Paragraph 1</a> <a href="#p2">Paragraph 2</a> ... </div> and set it to have a fixed position: #menu { position: ...

Any tips or hacks for successfully implementing vw resizing on the :before pseudo-element in webkit browsers?

When using vw sizes on webkit browsers, a well-known bug can occur where they do not update when the window is resized. The typical workaround for this issue has been to employ javascript to force a redraw of the element by reassigning the z-index upon res ...

Encountering an error: "Unable to assign the 'id' property to an undefined object while attempting to retrieve it"

I'm running into an issue while attempting to retrieve a specific user from Firebase's Firestore. export class TaskService { tasksCollection: AngularFirestoreCollection<Task>; taskDoc: AngularFirestoreDocument<Task>; tasks: Obs ...

The previous and next buttons are displaying side by side rather than being positioned at the outer edges

I am having an issue where the prev and next buttons are displaying next to each other instead of at the edge of the div. Can someone please assist me in fixing this problem? Below is the provided HTML code: <div id ="moreOption_80322271" class="m ...

Adjust the sizes of the points according to the level of zoom

I've been working on creating a dynamic map in d3.js that displays US Science funding agencies as points, with their sizes scaling based on zoom level. I referred to this starter kit for guidance. While there are other solutions out there, they often ...

Send a file using ajax with the help of JavaScript and PHP

Currently, I am looking to implement a method for uploading files using Ajax and JavaScript/PHP without having the page refresh. My initial thought is to use Ajax to send the file using xmlhttp.send(file) and then retrieve it in the PHP script, but I' ...

Extracting JSON data from an ASP.NET MVC controller action to an AJAX.ActionLink

I am currently working on an asp.net mvc application and I have added an action link in the following manner: <%= Ajax.ActionLink("Event Notifications", "processCallrecording", new { Id = ViewData["RecordingIDsEdit"] }, new AjaxOptions { OnSuccess ...

Leveraging reframe.js to enhance the functionality of HTML5 video playback

I'm struggling with using the reframe.js plugin on a page that includes HTML5 embedded video. When I try to use my own video file from the same folder, it doesn't work as expected. While everything seems to be working in terms of the page loadin ...

Module not found in Node.js environment (webpack)

I seem to be encountering an issue with loading any modules. Despite reinstalling my operating system, I continue to face the same error when attempting to use any module. I have tried reinstalling node, clearing the cache, and more. To view the code, pl ...

Unconventional border effect while hovering over image within navigation container of Bootstrap

Whenever I hover over the image inside the navigation bar, there is a strange white/gray border that appears. It's quite annoying. Does anyone know how to remove this border? Here is the code snippet causing the issue: <ul class ...

Creating a dynamic table in AngularJS that can add rows and columns with cyclic values

Seeking assistance for a programming challenge. I have created a form with 2 input fields for specifying the dimensions of a table (number of rows and columns), along with a button. When this button is clicked, the table should be dynamically populated wit ...

filling out a form with data retrieved through an ajax request

After retrieving JSON data from an MVC controller, I am attempting to populate a form with this data but encountering difficulties. The returned data consists of only one row with three properties. Despite confirming that the data is being returned success ...

Ensure that the header stays centered on the page as you scroll horizontally

Below is a given code snippet: header { text-align: center; } /* This section is just for simulation purposes */ p.text { width: 20rem; height: 50rem; } <html> <body> <header> <h1>Page Title</h1> <detail ...

Problem encountered in NextJS/ReactJS when attempting to dynamically load a new component by clicking a button within the current component

In my NextJS project, I am working with 3 components named "Sidebar", "Woven", and "ToolsPage". Below are the respective codes for each: ToolsPage Component: "use client" import Woven from './components/weaved'; import Sidebar from &ap ...

Having difficulty with PHP code, attempting to output some HTML while also opening a file and displaying its contents

I'm completely new to PHP and I've been experimenting with some code to display button elements that, when pressed, should open a file and write a number to it. Unfortunately, the code doesn't seem to be working as expected and I'm stru ...

When using @mouseover, it is not possible to modify a variable's value

The hover event is not functioning properly in this Vue component. Although I was able to call a function on hover successfully, I encountered issues when trying to change the hover variable directly. <template> <div @mouseover="hover = t ...

Tips for changing color when hovering over elements in a CSS grid

I am currently attempting to incorporate a hover effect into this CSS grid, but I have not been successful in my efforts. I experimented with transition and opacity techniques, but they did not work as expected. Can someone please point out what I may be ...