locked
the javasript function is not called, Please help RRS feed

  • Question

  • User-1355965324 posted

    I am trying to call the function GetBreakDownLog  when I change the LogYear. But After changing the year , the function is not called. Please can you help why the function is not called

    <div class="col-sm-3">
                            <input type='text' id="txtYear" asp-for="LogYear" class="form-control" onchange="GetBreakDownLog()" />
                        </div>
    <script type="text/javascript">
    
    $(document).ready(function () {
    
            $("#DateInvoicedPicker").datepicker({ format: 'dd/mm/yyyy', date: new Date(1900, 01, 01), autoclose: true, todayBtn: 'linked' });
            $("#DateWorkCarridPicker").datepicker({ format: 'dd/mm/yyyy', date: new Date(1900, 01, 01), autoclose: true, todayBtn: 'linked' });
           
             
    
        });
    
     function GetBreakDownLog() {
            var report = {};
            report.depot = "@Model.DepotNo"
            report.department = "@Model.DepartmentID"
            report.logyear = "@Model.LogYear"
            report.logmonth = "@Model.LogMonth"
            
    
            $('#BreakDownLog').DataTable({
                "processing": true,
               
    
                "ajax": {
                    "url": "/Employee/GetBreakDownLog",
                    "data": report,
                    "dataSrc": function (json) {
                        return JSON.parse(json);
                    }
                },
                "columns": [
                    { "data": "EmployeeName" },
                    { "data": "FromDate" },
                    { "data": "ClockedIn" },
                    { "data": "ClockedOut" },
                    { "data": "NetClockedHrs" },
                    { "data": "DueHrs" },
                    { "data": "BreakHrs" },
                    { "data": "VarianceHrs" },
                    { "data": "CumVarianceHrs" },
                    { "data": "NormalHrs" },
                    { "data": "HolidayHrs" },
                    { "data": "SickHrs" },
                    { "data": "DayoffHrs" },
                    { "data": "MaternityHrs" },
                    { "data": "TimeOffHrs" },
                    { "data": "ExtraTimeHrs" }
    
    
    
                ],
                "pageLength": 40,
                scrollY: "300px",
                scrollX: true,
                paging: true
                 
    
                
    
                  
            });
    
    
    
        }
    
         
    </script>

    In Controller

    public JsonResult GetBreakDownLog(BreakDownLogEntryModel report)
    {

    List<BreakDownLogEntryModel> BreakdownlogList = new List<BreakDownLogEntryModel>();
    DataSet ds = ReportBLL.GetBreakDownLogForDepot(connectionSettings,
    report.DepotNo, report.DepartmentID, report.LogYear, report.LogMonth
    );

    String jsonResult = JsonConvert.SerializeObject(BreakdownlogList);
    return Json(BreakdownlogList);

    }

    Monday, September 9, 2019 2:02 PM

Answers

  • User475983607 posted

    I put the breakpoint  in   controller inside   function GetBreakDownLog and the function is not called . I am passing txtYear from the model

    This post is similar to your others where you simply do not debug your code.  Why?

    The code does NOT pass txtYear to the JavaScript!  It passes whatever was in the model passed to the view which is not clear form your code.  Please take a few moments to open the brower's dev tools (F12) and debug your code!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2019 5:56 PM

All replies

  • User-474980206 posted
    Use the browsers debug tools to see if there are any syntax errors. Try a breakpoint in the called function, use the network tools to see the response to the Ajax call if made.
    Monday, September 9, 2019 2:58 PM
  • User475983607 posted

    The value of txtYear is not POSTed to the /Employee/GetBreakDownLog action. 

    Are you sure the onchange event is not firing?  Are you using dev tools to verify the GetBreakDownLog() function is not called and the AJAX request does not happen?  HAve you checked for error?  Can you explain how you are testing?  

     

    Monday, September 9, 2019 3:01 PM
  • User-1355965324 posted

    I put the breakpoint  in   controller inside   function GetBreakDownLog and the function is not called . I am passing txtYear from the model

    @model BreakDownLogEntryModel
    <label for="lblYear" class="control-label col-sm-1 ">Year</label>
    <div class="col-sm-3">
    <input type='text' id="txtYear" asp-for="LogYear" class="form-control disabled" onchange="GetBreakDownLog()" />
    </div>
    
    report.depot = "@Model.DepotNo"
    report.department = "@Model.DepartmentID"
    report.logyear = "@Model.LogYear"
    report.logmonth = "@Model.LogMonth"

    Monday, September 9, 2019 3:29 PM
  • User475983607 posted

    I put the breakpoint  in   controller inside   function GetBreakDownLog and the function is not called . I am passing txtYear from the model

    This post is similar to your others where you simply do not debug your code.  Why?

    The code does NOT pass txtYear to the JavaScript!  It passes whatever was in the model passed to the view which is not clear form your code.  Please take a few moments to open the brower's dev tools (F12) and debug your code!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2019 5:56 PM
  • User-1355965324 posted

    Many Thanks

    Monday, September 9, 2019 9:21 PM