Welcome visitor
* Login
* Register
It is currently May 23rd, 2019, 8:53 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » HTML



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  An easy form to count days
PostPosted: November 22nd, 2009, 4:56 am 

Posts: 17
Hello, I'm looking for a simple, nothing complex, form in which the user can enter 2 dates and then calculate the days in between. Do you know where I can find something for this?


Top
 Profile  
 
  Re: An easy form to count days
PostPosted: November 22nd, 2009, 6:55 am 

Posts: 117
HTML is a Markup Language, no interaction at all. The solution I provided is based on JavaScript. A server side solution could be an option too.
  <form action="#">
  beginning&nbsp;&nbsp;
    <input id="hd" class="d" value="dd" />-
    <input id="hm" class="m" value="mm" />-
    <input id="ha" class="a" value="aaaa" />
  <br /><br />
  end&nbsp;&nbsp;
    <input id="td" class="dd" value="dd" />-
    <input id="tm" class="mm" value="md" />-
    <input id="ta" class="aa" value="aaaa" />
  <br /><br />
    <input type="button" value="count days!" onclick="mcd();" />
  </form>


<script type="text/javascript">
function mcd(){
  hd=Number(document.getElementById('hd').value);
  hm=Number(document.getElementById('hm').value)+1;
  ha=Number(document.getElementById('ha').value);
  var h=new Date();
  h.setFullYear(ha,hm,hd);
  td=Number(document.getElementById('td').value);
  tm=Number(document.getElementById('tm').value)+1;
  ta=Number(document.getElementById('ta').value);
  var t=new Date();
  t.setFullYear(ta,tm,td);
  ms = t.getTime()-h.getTime();
  s = ms/1000;
  m = s/60;
  h = m/60;
  d = h/24;
  days = Math.ceil(d);
  alert(days);
}
</script>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » HTML


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron