SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Tennessee
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with calendar date disabling

    Hey all i have this piece of code before that disables the given dates i put into an array. This works great for day 2-30 (out of a 31 day month) but it does not seem to work when i select either day 1 or day 31.

    For day 1 it blocks out day 1 and i do not want that. The user should be able to select that day since it was selected. It does not do this for any other day. If the user selects day 2 then day 2 is selected on the calender and is not blocked.

    As for day 31, i don't know whats wrong with it because it never shows me an error. It's the type of error that shuts down the website with "System Unavailable" for about a minute before i can connect to the page again.

    Here is my code:
    Code:
    var disabledDays = ['3-31-2010','3-30-2010','3-29-2010','3-28-2010','3-27-2010','3-26-2010','3-25-2010','3-24-2010','3-23-2010','3-22-2010','3-21-2010','3-20-2010','3-19-2010','3-18-2010','3-17-2010','3-16-2010','3-15-2010','3-14-2010','3-13-2010','3-12-2010','3-11-2010','3-10-2010','3-9-2010','3-8-2010','3-7-2010','3-6-2010','3-05-2010'];
     
    	function nationalDays(date) {
    	var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
    
    	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
    				
    	for (i = 0; i < disabledDays.length; i++) {
    		if(ArrayContains(disabledDays,(m+1) + '-' + d + '-' + y) || new Date() > date) {
    			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
    			return [false];
    		}
    	}
    		//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
    		return [true];
    	}
    		
    	function noWeekendsOrHolidays(date) {
    		return nationalDays(date);
    	}
     
    	function ArrayIndexOf(array,item,from){
    	var len = array.length;
    
    	for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
    		if (array[i] === item) return i;
    	}
    		return -1;
    	}
    			
    	function ArrayContains(array,item,from){
    		return ArrayIndexOf(array,item,from) != -1;
    	}
    Any help would be great!

    David

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StealthRT View Post
    Here is my code:
    What test HTML code would you use for a sample calendar?

    I ask this so that we can simulate your situation, so that our solution will most easily work in your own situation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Tennessee
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a page where i have the test site on. Maybe that will allow you to make a better judgement call about my profile?

    http://www.nextbowluser.com/cal/final/basic-views.html

    Set your date on your pc to march 1st so you know what i am talking about once you click on the day 1.

    David

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StealthRT View Post
    I have a page where i have the test site on. Maybe that will allow you to make a better judgement call about my profile?

    http://www.nextbowluser.com/cal/final/basic-views.html
    Thank you for that. It will make it all the easier for someone to help you with this.

    Quote Originally Posted by StealthRT View Post
    Set your date on your pc to march 1st so you know what i am talking about once you click on the day 1.
    I am not in a position to make that sort of change to my system, so hopefully someone else will be able to help.

    If it any consolation, it doesn't appear that the code you posted is responsible for the issue at hand.

    You may though, want to use the more official compatibility code for Array.indexOf

    Code javascript:
    if (!Array.prototype.indexOf)  
    {  
      Array.prototype.indexOf = function(elt /*, from*/)  
      {  
        var len = this.length >>> 0;  
     
        var from = Number(arguments[1]) || 0;  
        from = (from < 0)  
             ? Math.ceil(from)  
             : Math.floor(from);  
        if (from < 0)  
          from += len;  
     
        for (; from < len; from++)  
        {  
          if (from in this &&  
              this[from] === elt)  
            return from;  
        }  
        return -1;  
      };  
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •