Monday, February 23, 2015

convert time to seconds in javascript (prototype method)


Example code for convert time to seconds.

String.prototype.toSEC = function () {
value = this;
formats = value.split(":");
s = 0; m = 0; h = 0; res = 0;
if(formats.length>2) s = formats[2];
if(formats.length>1) m = formats[1];
if(formats.length>0) h = formats[0];
res += (parseInt(h)*3600);
res += (parseInt(m)*60);
res += parseInt(s);
return res;
}
time = '11:45:00';
time.toSEC();

Bind Some Event to Element and trigger that function when click the element

Scenario: Suppose if we used same click event function in various web pages. if you want do some logic some page button for that need to re...