Having trouble retrieving the date from the datepicker with ng-model and ng-click functionality

My goal is to develop a small web application where users can download data from a database within a specified time range. Below is the HTML code snippet that I have:

<div class="container">
            <div class='col-md-5'>
                Start Date:
                <div class="form-group">
                    <div class='input-group date' id='datetimepicker6'>
                        <input type='text' ng-model="queryDate.start" class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>
            <div class='col-md-5'>
                End Date:
                <div class="form-group">
                    <div class='input-group date' id='datetimepicker7'>
                        <input type='text' ng-model="queryDate.end" class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>


            <div class='col-md-5'>
                Service Name:
             <select id="serviceName" style="font-size: 15px;padding: 5px;width: 300px" >
                 <option></option>
                 <option ng-repeat="webService in webServices">{{ webService.fields.service }}</option>
             </select>
            </div>

            <div class='col-md-6'>
                <button type="button" id="download" ng-click="download(queryDate)" class="btn btn-theme" style="float: right">Download</button>
            </div>
        </div>

I am aiming to capture both the start date and end date using ng-model.

ng-model="queryDate.start"

ng-model="queryDate.end"

Handling data from ng-model should be straightforward, as demonstrated in the AngularJS documentation here.

Here is my mainApp.js file:

var mainApp = angular.module("mainApp",[]);
mainApp.controller("serviceController",function($scope,$http){
$http.get("/fetchData/").success(function(response){
    $scope.webServices = response;
});
//--------- I receive an alert saying "Hola," but the subsequent alert shows "undefined" ---------
$scope.download = function(queryDate){
    alert('Hola');
    alert(queryDate);
  };
});

The intention is to gather input from the date fields and utilize them to fetch relevant data from the database.

Answer №1

<div class='input-group date' >
                        <input type='text' ng-model="queryDate.start" id='datetimepicker6'class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>

To implement this in your JavaScript file, use the code snippet below: $('#datetimepicker6').datepicker();

Make sure to include the jQuery UI library for the datepicker functionality.

For a detailed example, visit https://jqueryui.com/datepicker/

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

From time to time, I may post files of substantial size

When moving to the next step in the form, I have implemented checks to prevent photos over 10mb and disallow .heic files from being uploaded. Most of the time it works as expected, but occasionally files slip through. If anyone has suggestions for a more ...

QUnit disregard error originating from the source

After writing tests for my Bacon.js functions using jQuery's qUni, I'm encountering an issue. Even though the outcome is correct and the equals() methods work as expected, qUnit marks the test as failed due to an error thrown by Bacon.js. Is the ...

Exploring the implementation of async/await in JavaScript frontend for fetching data from a node.js backend asynchronously

To sidestep any cross origin problems, I have set up a front end JavaScript code that is connecting to a backend Node.js server. This server, in turn, is accessing data from an API on a different domain: const API_URL = [SOME_OTHER_SERVER]; const API_TIME ...

PHP Array Output: Understanding the Basics

I am relatively new to PHP and faced with a challenge. I have an array $companyStates = array("AR","TX","LA","OK","GA","NC","SC"); It contains a list of US states. My goal is to do two simple tasks with this array: 1) print the values in this format: ART ...

What could be causing the malfunction of the map function, despite the code appearing to be correct?

I have encountered an issue in my React functional component where I am trying to display a list of notifications. The useEffect() function is being called to generate the "data" which should then be displayed on the page. The code seems to be running fine ...

What is the best way to send multiple requests consecutively using the riot-lol-api?

SCENARIO: Recently, I found myself dealing with an existing codebase that relied on a different library for making requests to the Riot API. Due to some issues with the current library, I made the decision to transition to a new one: https://www.npmjs.co ...

Pass intricate JavaScript object to ASP.Net MVC function

It appears that many people have shared helpful answers on a common topic, but I am still facing difficulties in making my attempt work. The issue is similar to the one discussed here, however, I am only trying to send a single complex object instead of a ...

Using a conditional statement in conjunction with the jQuery .animate function

As a complete novice with Javascript and jQuery, I am attempting to animate a div only if a specific variable is true, but unfortunately, it's not functioning as expected. Can someone offer guidance on how to resolve this issue? Below is the code I h ...

Skip the "required" attribute in HTML forms for submission

Before submitting a form, I rely on the use of required for initial validation. <form action = "myform.php"> Foo: <input type = "text" name = "someField" required = "required"> <input type = "submit" value = "submit"> <input typ ...

Retrieve information attribute within VueJS

Within a v-for loop, I am utilizing a select form in the following manner: <div class="select"> <select v-model="shippingMethod"> <option value="{{shipping.id}}" v-for="shipping in shippingMethods" data-price="{{ shipping.amount ...

Troubleshooting: Issue with revalidate functionality in NextJS getStaticProps

I'm working on a NextJS site that uses getStaticProps to fetch data from Firestore. My code looks like this: return { props: { allPosts: posts, }, revalidate: 60, } As far as I know, this should refresh the data from firebase eve ...

What is the best way to specify a function parameter as a Function type in TypeScript?

I'm currently delving into the world of TypeScript and I am unsure about how to specify a function parameter as a function type. For instance, in this piece of code, I am passing a setState function through props to a child component. const SelectCity ...

Positioning the camera relative to a 3D object in three.js

I am facing a challenge where I need to ensure that the camera stays at a fixed distance behind an object as it moves and rotates. Specifically, I am working on drawing an airplane and require the camera to always focus on its rear end, while allowing user ...

What is the impact of util.inherits on the prototype chain in JavaScript?

Exploring this particular design: Function ConstrA () { EventEmitter.call(this); } util.inherits(ConstrA, EventEmitter); var obj = new ConstrA(); If util.inherits is omitted, ConstrA and obj will each establish their own distinct prototype chain. T ...

What is the best way to pass the values of two interlinked drop-down menus through an AJAX post request to a Django view?

Presently, I am encountering an issue with sending the values of two dropdowns to a django view. My code would have functioned correctly if the dropdowns were independent. Unfortunately, this is not the case as the first one updates the second one. Therefo ...

The compilation of PKG using Axios 1.x encounters an error

Despite attempting numerous strategies, I have not been successful. I developed a Node.js application with API requests managed using axios. However, I am unable to convert it into an executable file. Trying to downgrade Axios to version 0.27.0 resolved th ...

Using regular expressions, you can eliminate a specific segment of a string and substitute

Provide a string in the following format: lastname/firstname/_/country/postalCode/_/regionId/city/addressFirst/addressSecond/_/phone I am creating a function that will extract the specified address parts and remove any extra parts while maintaining maxim ...

How can I effectively save data to a session using connect-redis?

I am looking to save the username of an account into session storage. I am currently using node.js with the expressjs framework and have attempted to utilize connect-redis for storing sessions, following a tutorial on expressjs. Can someone please guide ...

The $q.all promise is always fulfilled without being chained to then

While going through the feeds.forEach cycle, one of my promises ends up throwing an error. I suspect that this is happening because the line $rootScope.links = urls; inside the then block in LoadData is never being executed. How can I resolve this issue? ...

javascript The event handler is not functioning properly for the dynamically loaded AJAX content

I am facing an issue with adding a JavaScript event listener to a dynamically loaded div via AJAX. Below is my code snippet: var QuantityMiniCart = function() { var infor = document.querySelectorAll( '.mini-cart-product-infor' ); if ( ...