I have a trouble with jquery each. this each block;
$(document).ready( function(){
$('td.trh').each(function(index) {
frk=fark($(this).text()); // frk useless variable
$('td.sure').eq(index).text(frk); // can be $('td.sure').eq(index).text(fark($(this).text()));
});
});
td.trh have date like “2012-03-02 11:25:30” and i have try to calculate the time passing over.. thats perfectly worked for first item but after that every loop stop working.
if i call a function like simdi(); without parameter,each perfectly worked..
fark function like;
function saat(trh){ //trh=2012-03-02 11:25:30
kes=trh.indexOf(' ');
kes++;
saat = trh.substring(kes); //saat=11:25:30
sparca = saat.split(":");
sTOsn=sparca[0] * 60 * 60; //sparca[0]=11 and 60*60 for hour to sec conversion
dkTOsn=sparca[1] * 60; //sparca[1]=25 and 60*60 for minute to sec conversion
sn=sparca[2] * 1;
sn=sTOsn+dkTOsn+sn; // all of this saat function for calculate time in sec
return sn;
}
function simdi() {
var now = new Date();
var s = now.getHours();
var dk = now.getMinutes();
var nsn = now.getSeconds();
sTOsn=s * 60 * 60;
dkTOsn=dk *60;
rsn = nsn + dkTOsn + sTOsn; // all of this simdi function for calculate current time in sec
return rsn;
}
function fark(trh) {
ssaat=saat(trh); // parameter date calculating in sec
suan=simdi(); // current date calculating in sec
snc=suan-ssaat; // calculating beetween parameter date and current date time difference
hh= snc / 3600 | 0;
mm= (snc - (hh*3600)) / 60 | 0;
ss= snc % 60;
return (hh < 10 ? "0" : "") + hh + (mm < 10 ? ":0" : ":")+ mm + (ss < 10 ? ":0" : ":")+ ss; // and formating time differenc like hour:minute:second
}
Statement
overrides your function
saat. Change it toand the next statement to
You should always use
varin front of local variables in the function so that they don’t become global and polute the global namespace (and cause problems like this).