Page 1 of 1

Update text onChange

Posted: Thu May 13, 2004 9:56 am
by mgmweb
I have two date textfields who are popolated by a javascript (pop up calendar where you pick the date and the date populates the text field.) Under those I have a dynamic PHP text that calculates the days between the two dates.

I currently use the update (Submit) button on the form to activate the PHP code that calculates the days between.

Is it possible to write the code so it automatically changes the "Days between:" value when the last text field has been populated so that people can see how many days it is between the two dates BEFORE they push the submit button.?! Excuse my bad english i`m norwegian

My PHP code if anyone needs it:

<?PHP
$dateRegExp = "#^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{2,4})$#ies";
$timestamp1 = preg_replace( $dateRegExp, "mktime(0, 0, 0, '\\2', '\\1', '\\3')", $_POST["txtAnk"] );

$timestamp2 = preg_replace( $dateRegExp, "mktime(0, 0, 0, '\\2', '\\1', '\\3')", $_POST["txtAvr"] );

$dateDiff = $timestamp2 - $timestamp1;
$test = floor(dateDiff/60/60/24);
echo 'Du ønsker å reservere '. floor($dateDiff/60/60/24). ' dag(er).';
echo '<br />Du ønsker å reservere '. ($test). ' dag(er).';
?>

Posted: Thu May 13, 2004 10:54 am
by xisle
you'll have to write the code in Javascript if you want to use as an
onChange event. PHP is a server-side language hence the necessity
to post the form...