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">
$(document).ready(function () {
$('#MainContent_rblProductive input').click(function () {
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") {
$('#MainContent_lblState').text(state);
}
else {
alert("Error");
}
},
error: function (error) {
}
});
}
});
});
$(document).ready(function () {
$('#MainContent_rblNoProductive input').click(function () {
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") {
$('#MainContent_lblState').text(state);
}
else {
alert("Error");
}
},
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;
}
}
}
}
}
$(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") {
alert("Goodbye")
window.location.href = 'Login.aspx';
}
else {
alert(status);
}
},
error: function (error) {
}
});
});
});
<script type="text/javascript">
$(document).ready(function () {
$('#MainContent_rblProductive input').click(function () {
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") {
$('#MainContent_lblState').text(state);
}
else {
alert("Error");
}
},
error: function (error) {
}
});
}
});
});
$(document).ready(function () {
$('#MainContent_rblNoProductive input').click(function () {
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") {
$('#MainContent_lblState').text(state);
}
else {
alert("Error");
}
},
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;
}
}
}
}
}
$(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") {
alert("Goodbye")
window.location.href = 'Login.aspx';
}
else {
alert(status);
}
},
error: function (error) {
}
});
});
});
function RefreshResults(id) {
var refreshFunction = document.getElementById('" + Refresh.Id + "').onclick;
refreshFunction();
return false;
}
var intervalId = setInterval('RefreshResults()', 100);
</script>
</script>