SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Resolved] Several instances of the same function

    Hi,

    I'm struggling on a JS function to generate calendars.
    It works fine until I have more than one instance. Then, when I change the month in the first instance, it's the 2nd one which makes the change.
    I don't understand very well how I should build my function.

    Can you tell me what I have to do in order to get the methods applied to the right instance?

    Here after is a brief extract from the way I built my function (I spare you the 500 lines).

    Code:
     
    function calendar(FieldId)
    {
    	var me = this;
    	me.SelectedDays = Array();
    	//etc
     
    	GoNextMonth = function(){
    	//blabla
    	}
    	me.NextMonthButton = document.createElement('div');
    	me.NextMonthButton.onclick=GoNextMonth();
    }
    PS: I use the word 'instance' but my function is not a class, I call it using calendar('test'), not new calendar('test'))...


    Cheers!
    Last edited by nabab; Sep 19, 2007 at 08:33. Reason: [Resolved]

  2. #2
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the code you've posted is fine.

    You shouldn't even need the parameter because THIS automatically picks up whatever element called it.

    One thing you might try immediately is using

    Code:
    var me = this.id;
    Just in case there's a problem with using this. I know this.id is stable, I've got a couple functions on my site that depend on it. See if that works.

    If not, it's probably a matter of your event handlers, post those and we'll take a look.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  3. #3
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for this.

    It was looking to work fine with 2 instances, but when I use the method Paint() or want to hide the calendar, a new DIV is created each time.

    My script is there:
    http://www.babna.com/cal/

    Please can you help??

    Cheers!

    Thomas

  4. #4
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, that works fine now.

    Thanks anyway for the help

  5. #5
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your welcome!
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


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
  •