Results 1 to 3 of 3

Thread: Code for accessing data from another file

  1. #1
    Join Date
    Jul 2012
    Location
    Dorset, England
    Posts
    67
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Code for accessing data from another file

    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 ?

    Code:
    <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
    Last edited by Mark Ellis; 08-01-2012 at 10:24 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
       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:

    Code:
    <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:

    Code:
    <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.
    Last edited by jscheuer1; 08-02-2012 at 12:55 AM. Reason: English usage
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Mark Ellis (08-01-2012)

  4. #3
    Join Date
    Jul 2012
    Location
    Dorset, England
    Posts
    67
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Brilliant. Just what I was after

    Many thanks, John

    Mark

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •