javascriptjquerynode.jsdatepicker

Getting undefined data if i use onSelect in jquery datepicker


I am using nodejs in back-end, For date-picker i am using jquery plugin.

My end date should not be lesser that start date so i used the following code

<div class="ipfield">
           <label class="plclabel" for="role_type">Start Date</label> 
            <div class='input-group date' id='datetimepicker1'>
                <input type="text" name="startdate" id="datepicker1" ng-model="userdatas.start_date"  class="txt_box" id="datepicker1" autocomplete="off">

            </div>
          </div>


          <div class="ipfield">
           <label class="plclabel" for="role_type">End Date</label> 
            <div class='input-group date' id='datetimepicker1'>
                <input type="text" id="datepicker2" name="enddate" ng-model="userdatas.end_date"  class="txt_box" id="datepicker2" autocomplete="off">

            </div>
          </div>

  $( function() {
    $("#datepicker1").datepicker({
        changeMonth: true,
        minDate: dateToday,
        changeYear: true,
        dateFormat:'dd-M-yy',
        onSelect: function(selected) {
          $("#datepicker2").datepicker("option","minDate", selected)
        }
    });
    $("#datepicker2").datepicker({
         changeMonth: true,
         changeYear: true,
         dateFormat:'dd-M-yy',
        onSelect: function(selected) {
           $("#datepicker1").datepicker("option","maxDate", selected)
        }
    }); 
});

Am getting undefined data in back-end

 app.post('/add_notification', function (req, res, next) {
        console.log(req.body.msg['start_date'])
        console.log(req.body.msg['end_date'])
});

UPDATE:

Am sending the request through angularjs

var app = angular.module('app', ['countrySelect','ui.bootstrap','angularMoment','msl.uploads','angularFileUpload', 'ngMessages','ngTagsInput','ui-notification','angularUtils.directives.dirPagination']);

app.controller('settingsCtrl', function($scope, $http,$filter,Notification) 

{
     $scope.add_notification = function(msg){
          console.log(msg) // here itself am not getting the value
            $http.post('/add_notification',{'msg':msg}).then(function(response)
                {
                $('#editModal').modal('toggle');
                if(response.data=='error')
                   {   
                  Notification.error('<span class="glyphicon glyphicon-ok"></span><strong>Error !Please Try Again</strong>');   

                   }
                  else
                    {
                 Notification.success('<span class="glyphicon glyphicon-ok"></span><strong>Your news/event is saved and will be visible to all users for the time period choosen.</strong>');    
                    }

                $scope.load_notification();    
                }); 
             }
})

If i didn't use onSelect am getting the data, but my end date should not be lesser that start date.

is any mistakes in my code?


Solution

  • onselect occurs after a user selects (highlights) some text in an input or text area (documentation on w3schools).

    onchange refers to modifying an input or select element (documentation on w3schools).

    You might have better luck using a different event trigger that fires after the change you’re interested in (updating input) is completed.