javascript - calculate time difference from 24 hr select boxes -


i having trouble jscript function returning nan. have tried parseint on intime , outtime, neither works me. hoping guidance.

function diffhours (h1,m1,h2,m2,t) {     var intime = ((h1 * 60) + m1);     var outtime =((h2 * 60)+ m2);       /* converts total in minutes "hh:mm" format */     function totext (m) {         var minutes = m % 60;         var hours = math.floor(m / 60);          minutes = (minutes < 10 ? '0' : '') + minutes;         hours = (hours < 10 ? '0' : '') + hours;          return hours + ':' + minutes;     }      h1 = parseint(intime, 10);     h2 = parseint(outtime, 10);      var diff = h2 - h1;       document.getelementbyid(t).value = totext(diff) } 

i have 4 select boxes in document: hour in, minute in, hour out, minute out execute function onchange , should output readonly input difference in time. edit: here's input

<cfset timehour = ['','00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23']> <cfset timeminute = ['','00','01','02','02','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59']>  <td><cfselect name="sun_in_hh" id="sun_in_hh" onchange="diffhours('sun_in_hh','sun_in_mm','sun_out_hh','sun_out_mm','sun_total')">             <cfloop array="#timehour#" index="h">                 <option value="#h#">#h#</option>             </cfloop>         </cfselect>         <cfselect name="sun_in_mm" id="sun_in_mm">             <cfloop array="#timeminute#" index="m">                 <option value="#m#">#m</option>                                          </cfloop>         </cfselect></td> <td><cfselect name="sun_out_hh" id="sun_out_hh" onchange="diffhours('sun_in_hh','sun_in_mm','sun_out_hh','sun_out_mm','sun_total')">             <cfloop array="#timehour#" index="h">                 <option value="#h#">#h#</option>             </cfloop>         </cfselect>         <cfselect name="sun_out_mm" id="sun_out_mm">             <cfloop array="#timeminute#" index="m">                 <option value="#m#">#m#</option>                                             </cfloop>         </cfselect></td> <td><cfinput type="text" name="sun_total" id="sun_total" size=5></td> 

so case is, said coming select boxes

diffhours("22","45","23","15") or  diffhours("2j2","45","23","15") 

function diffhours (h1,m1,h2,m2,t) {      var intime = ((h1 * 60) + m1*1); // convert strings number       var outtime =((h2 * 60)+ m2*1);  // convert strings number           /* converts total in minutes "hh:mm" format */      function totext (m) {          var minutes = m % 60;          var hours = math.floor(m / 60);            minutes = (minutes < 10 ? '0' : '') + minutes;          hours = (hours < 10 ? '0' : '') + hours;            return hours + ':' + minutes;      }        h1 = parseint(intime, 10);      h2 = parseint(outtime, 10);        var diff = h2 - h1;          alert(totext(diff))  }  diffhours(22,45,23,15)  diffhours("22","45","23","15")  diffhours("2j2","45","23","15")


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -