Wrox Programmer Forums
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2005, 07:49 PM
Registered User
 
Join Date: Feb 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Two entries for March?

In the ch6_examp9.htm code, my month menus show up with no "Feb" and two entries for "Mar". Any idea why that could be?
 
Old March 5th, 2005, 07:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

A bug, maybe? ;)

Sorry, couldn't resist. Can you post your code so we can take a look at it?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 7th, 2005, 09:42 AM
Registered User
 
Join Date: Feb 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe you can spot a mistake I'm overlooking. When I downloaded the master code from Wrox it did the same thing.

----------

JavaScript functions...

function writeMonthOptions() {
    var theMonth;
    var monthCounter;
    var theDate = new Date(1);
    for (monthCounter = 0; monthCounter < 12; monthCounter++) {
        theDate.setMonth(monthCounter);
        theMonth = theDate.toString();
        theMonth = theMonth.substr(4, 3);
        document.write("<option value=" + theMonth + ">" + theMonth);
    }
}

function recalcDateDiff() {
    var myForm = document.form1;
        var firstday = myForm.firstDay.options[myForm.firstDay.selectedIndex].value;
        var secondDay = myForm.secondDay.options[myForm.secondDay.selectedIndex].value;
        var firstMonth = myForm.firstMonth.options[myForm.firstMonth.selectedIndex].value;
        var secondMonth = myForm.secondMonth.options[myForm.secondMonth.selectedIndex].value;
        var firstYear = myForm.firstYear.options[myForm.firstYear.selectedIndex].value;
        var secondYear = myForm.secondYear.options[myForm.secondYear.selectedIndex].value;
        var firstDate = new Date(firstDay + " " + firstMonth + " " + firstyear);
        var secondDate = new Date(secondDay + " " + secondMonth + " " + secondYear);
        var daysDiff = (secondDate.valueOf() - firstDate.valueOf());
        daysDiff = Math.floor(Math.abs((((daysDiff / 1000) / 60) / 60) / 24));
        myForm.txtDays.value = daysDiff;
        return true;
}


and the HTML for the month pull-down menu...

<select name="firstMonth" size="1" onchange="return recalcDateDiff()">
    <script language="JavaScript">
        writeMonthOptions();
    </script>
</select>
 
Old March 7th, 2005, 04:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I just copied and pasted the code in anew page, opened it in my browser, and I get 12 items, one for each month....

What happens when you comment out thus line:

theMonth = theMonth.substr(4, 3);

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Duality by Slipknot (Track 4 from the album: Vol. 3: (The Subliminal Verses)) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Duplicate Entries SaraJaneQ Classic ASP Databases 6 July 16th, 2006 10:47 PM
Automatic Entries on Forms taraj Access VBA 2 June 16th, 2006 07:37 AM
counting unique entries Figgis Access 5 November 23rd, 2005 07:01 PM
Wrox and Wrox.com FAQs (updated March 2, 2004) jminatel General Announcements 0 June 6th, 2003 09:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.