View Full Version : need help with ajax and onload for dhtml calendar

10-06-2008, 04:45 PM
Hi all,

im using a free dhtml calendar (from epoch) and have had no problems up to now.

the issue is that you initiate the calendar's relationship with a field in an onload event. such as:

<script type="text/javascript">
var reqdate_cal, plant_off_date_cal, plant_off_date_cal, itemreqdate_cal; //calendar popups!
window.onload = function () {
reqdate_cal = new Epoch('epoch_popup','popup',document.getElementById('reqdate'));
plant_off_date_cal = new Epoch('epoch_popup','popup',document.getElementById('plant_off_date'));
plant_on_date_cal = new Epoch('epoch_popup','popup',document.getElementById('plant_on_date'));
itemreqdate_cal = new Epoch('epoch_popup','popup',document.getElementById('itemreqdate'));

basically this sets up so that if you click on say, 'itemreqdate' field a new object is created.

due to the fact that i am using ajax to create more fields that need this relationship i need a way to get new lines into the onload.

the code i have on the bottom of the returned ajax is:

var oldWindowOnload = window.onload;
window.onload = function(e) {
if(oldWindowOnload) oldWindowOnload(e);
<php loops thru all fields>
echo "var itemreqdate{$row['id']}_cal = new Epoch('epoch_popup','popup',document.getElementById('itemreqdate{$row['id']}'));";
<end of php looping>
the 'var oldWindowOnload = window.onload' section just stops the first set of onload events being overwritten by the new set.

any ideas? im stumped...

10-09-2008, 03:55 PM
If you are setting that new window.onload code in the innerHTML of the page, it is not going to run. PLUS there is no onload event after the page has run.


10-10-2008, 09:07 AM
yeah - i know... i just wanted to know if there was a way to do an onload any other way?

10-15-2008, 09:33 AM
i added them to an image's onload and that worked fine :)