Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date selection field population problems

    Hey all, I am having a bit of difficulty sorting out where the problem may be in this script. Here is what is SUPPOSE to happen. When the page loads the drop downs should populate the year and month 6 months into the future. The form will be used as a delivery form. The days of the month should populate onChange. What happens is that the months and year do infact populate correctly but the days do not. It seems to be giving me the days from either the previous or following month rather than the selected month. This is not my code, it was just handed to me so deconstructing it and understanding it are giving me a bit of trouble. I hope you all can help.

    head
    Code:
    <script language="JavaScript">
    <!-- Original:  Ben McFarlin (mcfarlin@netscape.net) -->
    <!-- Web Site:  http://sites.netscape.net/mcfarlin -->
    
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    
    <!-- Begin
    	var currDate  = new Date();
    	var currYear  = parseInt(currDate.getFullYear());
    	var nextYear  = currYear + 1;
    	var currMonth = currDate.getMonth() + 1;
    	var currDay   = currDate.getDate();
    
    function populate(objForm,selectIndex) {
    	var m = parseInt(objForm.month.options[objForm.month.selectedIndex].value);
    	timeA = new Date (objForm.year.options[objForm.year.selectedIndex].text, // Chosen year
    			  m + 1 ,    						 // Next Month
    			  1); // [Chosen Year] 1, [Chosen Year]
    	timeB = new Date(timeA - 86400000); // Back one day
    	var daysInMonth = timeB.getDate();  // Number of days in the chosen month
    
    	for(var i = 0; i < 31; i++) {
    		objForm.day.options[i] = null;
    	}
    
    	if(m == currMonth) {
    		for(var i = (currDay + 1), j = 0; i <= (daysInMonth); i++, j++) {
    			document.form1.day.options[j] = new Option(i);
    		}
    	} else {
    		for (var i = 0; i < daysInMonth; i++) {
    			objForm.day.options[i] = new Option(i+1);
    		}
    	}
    
    	document.form1.day.options[0].selected = true;
    }
    
    function getYears() {
    	var years;
    	if(currMonth > 5) {
    		document.form1.year.options[0] = new Option(currYear);
    		document.form1.year.options[1] = new Option(nextYear);
    	} else if(currMonth == 12) {
    		document.form1.year.options[0] = new Option(nextYear);
    	} else {
    		document.form1.year.options[0] = new Option(currYear);
    	}
    
    	var months = new Array("",	"January", "February", "March", "April", 
    				"May", "June", "July", "August", 
    				"September", "October", "November", "December");
    	var blah;
    	if(currMonth == 12 && currDay == 31) {
    		blah = new Date(nextYear,
    				1,
    				1); // January, 1 [Next Year]
    	} else {
    		blah = new Date(currYear, 
    				currMonth + 1, 
    				1); // [Next Month], 1, [This Year]
    	}
    
    	var blahblah = new Date(blah - 86400000); // Go back one day
    
    	// Fill in the months
    	for(var i = currMonth, j = 0; j < 6; i++, j++) {
    		if(i > 12) { i = 1; }
    		document.form1.month.options[j] = new Option(months[i], i);
    	}
    
    	// Fill in the days
    	for(var i = (currDay + 1), j = 0; i <= (blahblah.getDate()); i++, j++) {
    		document.form1.day.options[j] = new Option(i);
    	}
    }
    //  End -->
    </script>
    body
    Code:
    
    <table border=0 width="100%">
                                      <tr>
    								    <td colspan="2"><b>Date and Time:<font color="#FF0000">*</font></b></td>
    								</tr>
                                      <tr> 
                                        <td>Date: </td>
                                        <td>
    					<select name=year onChange="populate(this.form,this.form.month.selectedIndex);">
    					</select>
    					<select name=month onChange="populate(this.form,this.selectedIndex);">
    					</select>
    					<select name=day>
    					</select>
    				    </td>
                                      </tr>
                                      <tr> 
                                        <td>Time :</td>
                                        <td>
    									<select name="time">
                                            <option value="" selected>Time</option>
                                            <option value="8:00 am">8:00 am</option>
                                            <option value="8:30 am">8:30 am</option>
                                            <option value="9:00 am">9:00 am</option>
                                            <option value="9:30 am">9:30 am</option>
                                            <option value="10:00 am">10:00 am</option>
                                            <option value="10:30 am">10:30 am</option>
                                            <option value="11:00 am">11:00 am</option>
                                            <option value="11:30 am">11:30 am</option>
                                            <option value="12:00 pm">12:00 pm</option>
                                            <option value="12:30 pm">12:30 pm</option>
                                            <option value="1:00 pm">1:00 pm</option>
                                            <option value="1:30 pm">1:30 pm</option>
                                            <option value="2:00 pm">2:00 pm</option>
                                            <option value="2:30 pm">2:30 pm</option>
                                            <option value="3:00 pm">3:00 pm</option>
                                            <option value="3:30 pm">3:30 pm</option>
                                            <option value="4:00 pm">4:00 pm</option>
                                            <option value="4:30 pm">4:30 pm</option>
                                            <option value="5:00 pm">5:00 pm</option>
                                            <option value="5:30 pm">5:30 pm</option>
                                            <option value="6:00 pm">6:00 pm</option>
                                            <option value="6:30 pm">6:30 pm</option>
                                            <option value="7:00 pm">7:00 pm</option>
                                            <option value="7:30 pm">7:30 pm</option>
                                            <option value="8:00 pm">8:00 pm</option>
                                            <option value="8:30 pm">8:30 pm</option>
                                            <option value="9:00 pm">9:00 pm</option>
                                            <option value="9:30 pm">9:30 pm</option>
                                          </select>
    									</td>
                                      </tr>
    here is the original script that was previously modified.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No offense to Javascript Kit but there have been better scripts which do what you want previously posted on the forum... Besides, tryng to fix unknown errors in an inferior, yet modified script, would be redundant when better ones are available...

    Try looking here:
    http://www.codingforums.com/showthread.php?t=41403

    .....Willy


  •  

    Posting Permissions

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