Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

calculate selected dates

Javascript coding ..

Moderators: macek, egami, gesf

calculate selected dates

Postby omicrazz » Wed Aug 17, 2011 11:42 pm

hiii im try to calculate 2 days..after the user selected a date..it should calculate automatically..any suggestion?? tq


Code: Select all
//this is my javascript

<script language="JavaScript" type="text/javascript">

function daysBetween(date1, date2) {
var day1, day2;
var month1, month2;
var year1, year2;

value1 = document.test2.t1.value;
value2 = document.test2.t2.value;

day1 = value1.substring (0, value1.indexOf ("/"));
month1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf ("/"));
year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);

day2 = value2.substring (0, value2.indexOf ("/"));
month2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf ("/"));
year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length);

date1 = year1+"/"+month1+"/"+day1;
date2 = year2+"/"+month2+"/"+day2;

firstDate = Date.parse(date1)
secondDate= Date.parse(date2)

msPerDay = 24 * 60 * 60 * 1000
 document.getElementById('total').value = Math.round((secondDate.valueOf()-firstDate.valueOf())/ msPerDay) + 1;


}
</script>

// this is the form

<form id="test2" name="test2" method="post" action="process.php">
<input name="t1" id="t1" class="required" title="select date" onClick="daysBetween()" />
<input name="t2" id="t2" class="required" title="select date" onClick="daysBetween()" />

<input name="total" id="total" size="2" onkeyup="daysBetween()" />
</form>



really appreciate if anyone could help
omicrazz
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Aug 11, 2011 4:43 am

Re: calculate selected dates

Postby lokanath7 » Mon Aug 29, 2011 7:52 am

ur code showing the difference between 2 dates...

what is ur question exactly ?
lokanath7
New php-forum User
New php-forum User
 
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron