javascript - How to calculate date difference in html using java script without clicking submit button -


i giving 2 dates manually in form after 1 more empty box there date difference should calculated in terms of days in third box dynamically using java script me working when clicking submit button , using submit button property want should calculated after entering second date second box , should display in third box here code.... please me out here..

script

   function datediff() {     date1 = new date();     date2 = new date();     diff = new date();     date1temp = new date(dateform.firstdate.value);     date1.settime(date1temp.gettime());     date2temp = new date(dateform.seconddate.value);     date2.settime(date2temp.gettime());     diff.settime(math.abs(date1.gettime() - date2.gettime()));     timediff = diff.gettime();     days = math.floor(timediff / (1000 * 60 * 60 * 24));     dateform.difference.value = days;     return false;    } 

html

<form>     <fieldset>         <label for="enter leave starting date">enter leave starting date             <input type="text" name="firstdate" />         </label>         <label for="enter leave ending date">enter leave ending date             <input type="text" name="seconddate" onkeyup="return datediff();" />         </label>        <label>          date difference (in days):  <input type=text name=difference>       </label>     </fieldset> </form> 

actually, code works...the thing need give form name use in script

<form name="dateform"> 

....i tested on fiddle, works charm: http://jsfiddle.net/byjkg/5/ ...tough might want check if datediff not nan

if(!isnan(days)){    dateform.difference.value = days; } 

[edit] ...i saw wasn't fiddle....but fiddle posted felix lahmer, source code


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -