Click here to Skip to main content
15,887,175 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionHow to trigger on change on a HTML5 var tag? Pin
Nicky Tse11-Nov-16 2:29
Nicky Tse11-Nov-16 2:29 
Rant[REPOST] How to trigger on change on a HTML5 var tag? Pin
Richard Deeming11-Nov-16 3:21
mveRichard Deeming11-Nov-16 3:21 
AnswerRe: How to trigger on change on a HTML5 var tag? Pin
Peter Leow11-Nov-16 3:41
professionalPeter Leow11-Nov-16 3:41 
QuestionUsing Javascript or JQuery to automatically click a div button Pin
Scott5210-Nov-16 10:21
Scott5210-Nov-16 10:21 
AnswerRe: Using Javascript or JQuery to automatically click a div button Pin
2374110-Nov-16 14:17
2374110-Nov-16 14:17 
GeneralRe: Using Javascript or JQuery to automatically click a div button Pin
Scott5211-Nov-16 2:34
Scott5211-Nov-16 2:34 
QuestionGoogle map Context Menu Pin
maher khalil7-Nov-16 4:47
maher khalil7-Nov-16 4:47 
QuestionShow list of data in table with set time out Pin
mrkeivan5-Nov-16 0:48
mrkeivan5-Nov-16 0:48 
Hey guys, I know the title is simple but I'm new to javascript and would appreciate if you could help me out

here's the deal,
I ve got some records that i read from database, and I want to add the to top of my table this is run every 20 seconds

JavaScript
var interval = setInterval(function () {     
        loadTableData(selectedOption);
    }, 20000);


here's what's happening inside loadTableData function

JavaScript
function loadTableData(dataType) {
    $.get("/JsonResultlink", null, function (result) {
        var itemAdd;
        $.each(result, function (i, item) {
            loadRecordTimeOut = setTimeout(function () {
                if (result[i].VEHICLEPLATE !== undefined) {
                    // build the html code
                    itemToAdd = generateRow(result[i], dataType);
                    // add to table body
                    $('.tto-violation-tablebody').prepend(itemToAdd);
                    // if rows exceed 50 remove from bottom
                    checkRowCount();
                }
            }, 1000 * i);
        });
        clearTimeout(loadRecordTimeOut);
    });
}


loadTableData is called in document ready and then every 2 seconds

Now I got 3 buttons that when each is clicked i call loadTableData with new dataType and show the result

now the problem is that in the middle of data being added to table i click one button I want the table to clear and the new data be displayed but what i get is that data loading becomes faster and i get both data from previous load and this load,

Please help me out and I'd like to learn clean coding so if you have any suggestions please let me know, appreciate it.

modified 5-Nov-16 6:59am.

AnswerRe: Show list of data in table with set time out Pin
Peter_in_27805-Nov-16 12:45
professionalPeter_in_27805-Nov-16 12:45 
QuestionHow to pass data from one html page to multiple html pages using javascript Pin
Sai Krishna27-Oct-16 2:08
Sai Krishna27-Oct-16 2:08 
AnswerRe: How to pass data from one html page to multiple html pages using javascript Pin
Richard Deeming27-Oct-16 2:17
mveRichard Deeming27-Oct-16 2:17 
GeneralRe: How to pass data from one html page to multiple html pages using javascript Pin
Sai Krishna27-Oct-16 18:38
Sai Krishna27-Oct-16 18:38 
GeneralRe: How to pass data from one html page to multiple html pages using javascript Pin
Richard Deeming28-Oct-16 2:18
mveRichard Deeming28-Oct-16 2:18 
GeneralRe: How to pass data from one html page to multiple html pages using javascript Pin
Sai Krishna30-Oct-16 18:28
Sai Krishna30-Oct-16 18:28 
GeneralRe: How to pass data from one html page to multiple html pages using javascript Pin
Richard Deeming31-Oct-16 3:27
mveRichard Deeming31-Oct-16 3:27 
AnswerRe: How to pass data from one html page to multiple html pages using javascript Pin
ZurdoDev31-Oct-16 4:40
professionalZurdoDev31-Oct-16 4:40 
QuestionHow to change the theme in javascript? Pin
Vayam Technologies Ltd. “Vayamtech” - New Delhi26-Oct-16 0:25
Vayam Technologies Ltd. “Vayamtech” - New Delhi26-Oct-16 0:25 
AnswerRe: How to change the theme in javascript? Pin
Rahul VB27-Oct-16 0:40
professionalRahul VB27-Oct-16 0:40 
GeneralRe: How to change the theme in javascript? Pin
Karthik_Mahalingam9-Nov-16 17:52
professionalKarthik_Mahalingam9-Nov-16 17:52 
GeneralRe: How to change the theme in javascript? Pin
Rahul VB9-Nov-16 23:24
professionalRahul VB9-Nov-16 23:24 
AnswerRe: How to change the theme in javascript? Pin
jkirkerx28-Oct-16 11:44
professionaljkirkerx28-Oct-16 11:44 
QuestionChange Image Background Using Javascript Pin
MadDashCoder24-Oct-16 14:48
MadDashCoder24-Oct-16 14:48 
SuggestionRe: Change Image Background Using Javascript Pin
ZurdoDev25-Oct-16 2:03
professionalZurdoDev25-Oct-16 2:03 
AnswerRe: Change Image Background Using Javascript Pin
Kornfeld Eliyahu Peter25-Oct-16 4:02
professionalKornfeld Eliyahu Peter25-Oct-16 4:02 
GeneralRe: Change Image Background Using Javascript Pin
MadDashCoder30-Oct-16 7:27
MadDashCoder30-Oct-16 7:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.