如何使用具有计时器间隔的javascript计时器自动将所选单选按钮值保存到数据库 [英] How do I automatically save selected radio button value to database using javascript timer with timer intervals

查看:86
本文介绍了如何使用具有计时器间隔的javascript计时器自动将所选单选按钮值保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个网络捕获表单,允许用户选择他们当前的任务。现在在某些情况下,用户可以在几分钟内保持相同的任务,我希望javascript中的计时器能够在每5分钟后自动保存用户所在的当前任务。



我尝试了一些例子,但没有成功。



这是我的代码如下:



 < script    类型  =  text / javascript >  
// window.onbeforeunload = function(evt) {
//
// var message ='请使用注销按钮';
// if(typeof evt =='undefined'){
// evt = window.event;
// }
< span class =code-comment> // if(evt){

// evt.returnValue = message;

// }

// 返回消息;
// alert(bye);

// }
/// / Updat生产率状态
$(文件).ready(function(){

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

// alert(请填写所有字段);
// }

// 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
成功:函数(结果,成功){

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


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


}
else {
alert( 错误);

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:功能(错误){




}

});

}
});
});
/// ////更新非生产时间状态
$(文件).ready(function(){

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

// alert(请填写所有字段);
// }

// else {

// $(#MainContent_rblNoProductive)。prop('checked',false);
// $(#MainContent_rblNoProductive)。removeAttr('che cked')

var state = $(' < span class =code-string>#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: < span class =code-string> json,
成功:函数(结果,成功){

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

// clear textboxes
// $('ContentPlaceHolder1_tb_UserName')。val();
// $('ContentPlaceHolder1_tb_Password')。val();

}
else {
alert( 错误 );

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:函数(错误){

}

});

}
});
});



函数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]。细胞;
for (j = 0 ; j < ; cell.length; j ++){
if (cell [j] .childNodes [ 0 ] .type == radio){
document.getElementById( cell [j] .childNodes [ 0 ]。id)。 checked = ;
}
}
}
}

}
函数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]。细胞;
for (j = 0 ; j < ; cell.length; j ++){
if (cell [j] .childNodes [ 0 ] .type == radio){
document.getElementById( cell [j] .childNodes [ 0 ]。id)。 checked = ;
}
}
}
}

}

/// / logout

$(document).ready(function(){

$(< span class =code-string>'
#btnLogout')。click(function(){

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


dataType: json
成功:函数(结果,成功){

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

}
其他 {
alert(status);

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:函数(错误){

}

});

});
});
< script type = text / javascript >
// window.onbeforeunload = function(evt){
//
// var message ='请使用注销按钮';
// if(typeof evt =='undefined'){
// evt = window .event;
// }
// if(evt){

// evt.returnValue =消息;

// }

// 返回消息;
// alert(bye);

// }
/// /更新生产力States
$(document).ready(function(){

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

// 警告(P租约填写所有字段);
// }

// 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
成功:函数(结果,成功){

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


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


}
else {
alert( 错误);

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:功能(错误){




}

});

}
});
});
/// ////更新非生产时间状态
$(文件).ready(function(){

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

// alert(请填写所有字段);
// }

// else {

// $(#MainContent_rblNoProductive)。prop('checked',false);
// $(#MainContent_rblNoProductive)。removeAttr('che cked')

var state = $(' < span class =code-string>#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: < span class =code-string> json

成功:函数(结果,成功){

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

// clear textboxes
// $('ContentPlaceHolder1_tb_UserName')。val();
// $('ContentPlaceHolder1_tb_Password')。val();

}
else {
alert( 错误 );

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:函数(错误){

}

});

}
});
});



函数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]。细胞;
for (j = 0 ; j < ; cell.length; j ++){
if (cell [j] .childNodes [ 0 ] .type == radio){
document.getElementById( cell [j] .childNodes [ 0 ]。id)。 checked = ;
}
}
}
}

}
函数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]。细胞;
for (j = 0 ; j < ; cell.length; j ++){
if (cell [j] .childNodes [ 0 ] .type == radio){
document.getElementById( cell [j] .childNodes [ 0 ]。id)。 checked = ;
}
}
}
}

}

/// / logout

$(document).ready(function(){

$(< span class =code-string>'
#btnLogout')。click(function(){

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


dataType: json
成功:函数(结果,成功){

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

}
其他 {
alert(status);

// $(#Login)。css(display,block );
// $(#Loading)。css(display ,无);
}

},
错误:函数(错误){

}

});

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

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

</script>

</script>

解决方案

(document).ready(function () {


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

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

// else {

//< /blockquote>

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


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:

<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>

解决方案

(document).ready(function () {


('#MainContent_rblProductive input').click(function () { // alert("Please fill in all fields"); // } // else { //


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


这篇关于如何使用具有计时器间隔的javascript计时器自动将所选单选按钮值保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆