PDA

View Full Version : Resolved Code for accessing data from another file



Mark Ellis
08-01-2012, 11:38 AM
Hi,

I want to access events from a separate file, rather than have to list them all in the main calendar htm file.

What code do I need to put in after "myCalendar.defineEvents([" in the code below ?


<script type="text/javascript">
var myCalendar = new JEC('myCalendarContainer');
myCalendar.defineEvents([
{
eventDate: 20120804,
eventDescription: 'Weymouth',
eventLink: 'http://www.dorsetdog.com/diary-of-dog-shows#wtg',
eventLinkTitle: 'A JavaScript Event Calendar'
},
{eventDate: 20120812,
eventDescription: 'Dorchester',
eventLink: 'http://www.dorsetdog.com/diary-of-dog-shows#wtg'
},
]);
myCalendar.showCalendar();
</script>

thanks

jscheuer1
08-01-2012, 04:41 PM
I wouldn't. Since there's very little else there besides the events, using a text only editor like NotePad I would make an external script like so:


var myCalendar = new JEC('myCalendarContainer');
myCalendar.defineEvents([
{
eventDate: 20120804,
eventDescription: 'Weymouth',
eventLink: 'http://www.dorsetdog.com/diary-of-dog-shows#wtg',
eventLinkTitle: 'A JavaScript Event Calendar'
},
{eventDate: 20120812,
eventDescription: 'Dorchester',
eventLink: 'http://www.dorsetdog.com/diary-of-dog-shows#wtg'
},
]);
myCalendar.showCalendar();

Save it as - say, mycalendarinit.js. Put it in the same folder as the page that's using it, and then replace the code from your post with:


<script src="mycalendarinit.js" type="text/javascript"></script>

You could even put it in another folder as long as you include the path to its location in the src attribute of the external script tag. Example:


<script src="http://www.mydomain.com/js/mycalendarinit.js" type="text/javascript"></script>

where the highlighted part is the path to it on the server.

Mark Ellis
08-01-2012, 10:24 PM
Brilliant. Just what I was after

Many thanks, John

Mark