This topic is locked

Adding a (number field) to a date on a _add page

3/16/2006 1:50:05 PM
PHPRunner General questions
D
Dale author

Can anyone point me to a solution on adding a number of days to a date to populate another date field.

Simply

Created Date: 03/16/2006 // My base date field using the now() on the default value.

Days Delay: 10 // A number field with validation to number.

Due Date: 03/26/2006 // (Trying to use script to add the 10 days to get this result.
There should be some functions in phprunner already maybe that I could call. I have modified one of the _add templates for a very customized form.
ANY pointers would be appreciated.

Sergey Kornilov admin 3/17/2006

Dale,
you can add some code to Before record added event on the Events Tab.

See my example:

function BeforeAdd(&$values)

{

$strSQLInsert = "insert into TableName (DueDate) values (DATE_ADD(".$values["CreatedDate"].",".$values["DaysDelay"]."))";

db_exec($strSQLInsert,$conn);

return true;

}

D
Dale author 3/17/2006

Thanks Sergey,

I am very impressed with the forum. I appreciate all the valuable information you give out.
My problem with adding the days needs to be a bit more immediate. Users hate to have to refresh or submit to see results. On my form I have 10 fields that need to be populated with number of days,

then each corresponding date must be updated on the form.
I use ajax to reach for the table information for the number of days to populate the current Add form.

Then I FINALLY figured out which value# and tsvalue# I needed to update. I used the below script to get the dates to add to the Days and update. Unfortunately, I have to have a button on the form to UPDATE to evoke the code to update all 10 dates. No submitting but still would be nice NOT to have to hit a button.

Works great.
I did find in the ..._functions.php where I could add an onblur event to the field, BUT then Im forced to update the ..._functions.php each time a build is done. Hence my suggestion earlier, It would be nice when Formatting the field you could enter functions to call when onBlur, onClick etc etc. Boy that would give you some nice power.
I changed dates to seconds, did the adding, then formatted the result for the appropriate value# and tsvalue# phprunner was using.
if (document.getElementById('value27').value)

{

var step1 = new Date();

var dateinms = step1.valueOf ();

var adddays = document.getElementById('value27').value;

if (adddays == 1) adddays = 0 ;

var msindays = 1000 60 60 24 adddays ;

var indays = new Date ( dateinms + msindays );
var today = indays;

var month = today.getMonth() + 1;

var day = today.getDate();

var year = today.getFullYear();
document.getElementById('value17').value = ((month < 10) ? '0' + month : month) +'/' + ((day < 10) ? '0' + day : day)+'/'+((year < 1000) ? year + 1900 : year);

document.getElementById('tsvalue17').value = ((day < 10) ? '0' + day : day) +'-' + ((month < 10) ? '0' + month : month) +'-' + ((year < 1000) ? year + 1900 : year);

}
Again, thanks for your response and all the great info you give out. I will definitely be able to use your suggestion here for other things. Thanks.

Great work. Great product.