Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have created a web capture form that allows users to select what their current task is. Now in some cases a user may stay on the same task for number of minutes and what I would like is for a timer in javascript to automatically save the current task the user is on after every 5 minutes.

I have tried a few example but did not work out.

Here is my code below:

C#
<script type="text/javascript">
//        window.onbeforeunload = function (evt) {
//
//                var message = 'Please use the logout button';
//                if (typeof evt == 'undefined') {
//                    evt = window.event;
//                }
//                if (evt) {

//                    evt.returnValue = message;

//                }

//                return message;
//             alert("bye");

//        }
    //// Updates Productivity States
        $(document).ready(function () {

            $('#MainContent_rblProductive input').click(function () {

                //                    alert("Please fill in all fields");
                //                }

                //                else {

                //  $("#MainContent_rblNoProductive").prop('checked', false);
                //   $("#MainContent_rblNoProductive").removeAttr('checked')

                var state = $('#MainContent_rblProductive input:checked').val();

                DeSelect_NonProductive();
                RefreshResults(state);
                if (state != "") {

                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "TimeStates.asmx/updateProductiveState",
                        data: "{state: '" + state + "'}",

                        dataType: "json",
                        success: function (result, success) {

                            var status = result.d;
                            if (status == "1") {
                                //                            $("#login").css("display", "none");
                                // response.redirect


                                $('#MainContent_lblState').text(state);


                            }
                            else {
                                alert("Error");

                                //                                $("#Login").css("display", "block");
                                //                                $("#Loading").css("display", "none");
                            }

                        },
                        error: function (error) {




                        }

                    });

                }
            });
        });
        /////// Updates Non Productive Time States
        $(document).ready(function () {

            $('#MainContent_rblNoProductive input').click(function () {

                //                    alert("Please fill in all fields");
                //                }

                //                else {

                //  $("#MainContent_rblNoProductive").prop('checked', false);
                //   $("#MainContent_rblNoProductive").removeAttr('checked')

                var state = $('#MainContent_rblNoProductive input:checked').val();

                DeSelect_Productive();
                RefreshResults(state);

                if (state != "") {

                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "TimeStates.asmx/updateNonProductiveState",
                        data: "{state: '" + state + "'}",

                        dataType: "json",
                        success: function (result, success) {

                            var status = result.d;
                            if (status == "1") {
                                //                            $("#login").css("display", "none");
                                // response.redirect
                                $('#MainContent_lblState').text(state);

                                //clear textboxes
                                //                                $('ContentPlaceHolder1_tb_UserName').val("");
                                //                                $('ContentPlaceHolder1_tb_Password').val("");

                            }
                            else {
                                alert("Error");

                                //                                $("#Login").css("display", "block");
                                //                                $("#Loading").css("display", "none");
                            }

                        },
                        error: function (error) {

                        }

                    });

                }
            });
        });



        function DeSelect_NonProductive() {
            var RB = document.getElementById("<%=rblNoProductive.ClientID%>");
            if (RB.rows.length > 0) {
                for (i = 0; i < RB.rows.length; i++) {
                    var cell = RB.rows[i].cells;
                    for (j = 0; j < cell.length; j++) {
                        if (cell[j].childNodes[0].type == "radio") {
                            document.getElementById(cell[j].childNodes[0].id).checked = false;
                        }
                                 }
                }
            }

        }
        function DeSelect_Productive() {
            var RB = document.getElementById("<%=rblProductive.ClientID%>");
            if (RB.rows.length > 0) {
                for (i = 0; i < RB.rows.length; i++) {
                    var cell = RB.rows[i].cells;
                    for (j = 0; j < cell.length; j++) {
                        if (cell[j].childNodes[0].type == "radio") {
                            document.getElementById(cell[j].childNodes[0].id).checked = false;
                        }
                    }
                }
            }

        }

        ////logout

        $(document).ready(function () {

            $('#btnLogout').click(function () {

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Login.asmx/logout",


                    dataType: "json",
                    success: function (result, success) {

                        var status = result.d;
                        if (status == "1") {
                            //                            $("#login").css("display", "none");
                            // response.redirect
                            alert("Goodbye")
                            window.location.href = 'Login.aspx';
                            //clear textboxes
                            //                                $('ContentPlaceHolder1_tb_UserName').val("");
                            //                                $('ContentPlaceHolder1_tb_Password').val("");

                        }
                        else {
                            alert(status);

                            //                                $("#Login").css("display", "block");
                            //                                $("#Loading").css("display", "none");
                        }

                    },
                    error: function (error) {

                    }

                });

            });
        });
    <script type="text/javascript">
//        window.onbeforeunload = function (evt) {
//        
//                var message = 'Please use the logout button';
//                if (typeof evt == 'undefined') {
//                    evt = window.event;
//                }
//                if (evt) {

//                    evt.returnValue = message;

//                }

//                return message;
//             alert("bye");

//        }
    //// Updates Productivity States
        $(document).ready(function () {

            $('#MainContent_rblProductive input').click(function () {

                //                    alert("Please fill in all fields");
                //                }

                //                else {

                //  $("#MainContent_rblNoProductive").prop('checked', false);
                //   $("#MainContent_rblNoProductive").removeAttr('checked')

                var state = $('#MainContent_rblProductive input:checked').val();

                DeSelect_NonProductive();
                RefreshResults(state);
                if (state != "") {

                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "TimeStates.asmx/updateProductiveState",
                        data: "{state: '" + state + "'}",

                        dataType: "json",
                        success: function (result, success) {

                            var status = result.d;
                            if (status == "1") {
                                //                            $("#login").css("display", "none");
                                // response.redirect
                               

                                $('#MainContent_lblState').text(state);
                            

                            }
                            else {
                                alert("Error");

                                //                                $("#Login").css("display", "block");
                                //                                $("#Loading").css("display", "none");
                            }

                        },
                        error: function (error) {




                        }

                    });

                }
            });
        });
        /////// Updates Non Productive Time States
        $(document).ready(function () {

            $('#MainContent_rblNoProductive input').click(function () {

                //                    alert("Please fill in all fields");
                //                }

                //                else {

                //  $("#MainContent_rblNoProductive").prop('checked', false);
                //   $("#MainContent_rblNoProductive").removeAttr('checked')

                var state = $('#MainContent_rblNoProductive input:checked').val();

                DeSelect_Productive();
                RefreshResults(state);

                if (state != "") {

                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "TimeStates.asmx/updateNonProductiveState",
                        data: "{state: '" + state + "'}",

                        dataType: "json",
                        success: function (result, success) {

                            var status = result.d;
                            if (status == "1") {
                                //                            $("#login").css("display", "none");
                                // response.redirect
                                $('#MainContent_lblState').text(state);

                                //clear textboxes
                                //                                $('ContentPlaceHolder1_tb_UserName').val("");
                                //                                $('ContentPlaceHolder1_tb_Password').val("");

                            }
                            else {
                                alert("Error");

                                //                                $("#Login").css("display", "block");
                                //                                $("#Loading").css("display", "none");
                            }

                        },
                        error: function (error) {

                        }

                    });

                }
            });
        });



        function DeSelect_NonProductive() {
            var RB = document.getElementById("<%=rblNoProductive.ClientID%>");
            if (RB.rows.length > 0) {
                for (i = 0; i < RB.rows.length; i++) {
                    var cell = RB.rows[i].cells;
                    for (j = 0; j < cell.length; j++) {
                        if (cell[j].childNodes[0].type == "radio") {
                            document.getElementById(cell[j].childNodes[0].id).checked = false;
                        }
                                 }
                }
            }

        }
        function DeSelect_Productive() {
            var RB = document.getElementById("<%=rblProductive.ClientID%>");
            if (RB.rows.length > 0) {
                for (i = 0; i < RB.rows.length; i++) {
                    var cell = RB.rows[i].cells;
                    for (j = 0; j < cell.length; j++) {
                        if (cell[j].childNodes[0].type == "radio") {
                            document.getElementById(cell[j].childNodes[0].id).checked = false;
                        }
                    }
                }
            }

        }

        ////logout

        $(document).ready(function () {

            $('#btnLogout').click(function () {

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Login.asmx/logout",
          

                    dataType: "json",
                    success: function (result, success) {

                        var status = result.d;
                        if (status == "1") {
                            //                            $("#login").css("display", "none");
                            // response.redirect
                            alert("Goodbye")
                            window.location.href = 'Login.aspx';
                            //clear textboxes
                            //                                $('ContentPlaceHolder1_tb_UserName').val("");
                            //                                $('ContentPlaceHolder1_tb_Password').val("");

                        }
                        else {
                            alert(status);

                            //                                $("#Login").css("display", "block");
                            //                                $("#Loading").css("display", "none");
                        }

                    },
                    error: function (error) {

                    }

                });

            });
        });
        function RefreshResults(id) {
            var refreshFunction = document.getElementById('" + Refresh.Id + "').onclick;
            refreshFunction();
            return false;
        }

        var intervalId = setInterval('RefreshResults()', 100);

        </script>

        </script>
Posted
Comments
[no name] 15-Apr-14 9:09am    
And you expect someone to go through all of this code to try and figure out what "did not work out" means?
ZurdoDev 15-Apr-14 9:20am    
You need to update this question and only show relevant code.
ZurdoDev 15-Apr-14 9:21am    
It's very simple. Debug the code and find out what's wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900