Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
|
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 September 28th, 2006, 09:29 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default selectedIndex is NULL or not an Object

When calling a function to validate dates in select fields, I get the error "selectedIndex is null or not an object". When I call the function when the field is changed, it works fine. Why can't the function see which index is selected when the form loads but it can when a field is changed? The error occurs when DOMonth.selectedIndex is referenced under "if (pudo == "do"). The code is as follows...

Code:
<script>
changedodate('do');
</script>

....(HTML/ASP)....

<select name="DOMonth" class="rrform" onChange="changedodate('do');">

.......

In .JS file:

function changedodate(pudo)
{
    var now = new Date();
    var currentyear = now.getYear();

    var PUMonth = document.RR.PUMonth;
    var PUDay = document.RR.PUDay;
    var PUYear = document.RR.PUYear;
    var DOMonth = document.RR.DOMonth;
    var DODay = document.RR.DODay;
    var DOYear = document.RR.DOYear;

    if (pudo == "pu")
    {
        if (!validdate(PUMonth.selectedIndex+1, PUDay.selectedIndex+1))
        {
            PUMonth.selectedIndex++;
            PUDay.selectedIndex = 0;

            DOMonth.selectedIndex = PUMonth.selectedIndex;
            DODay.selectedIndex = 1;
        }
        else
        {    
            DOMonth.selectedIndex = PUMonth.selectedIndex;
            DODay.selectedIndex = PUDay.selectedIndex+1;
            validdodate();
        }
    }

    if (pudo == "do")
    {
        if (!validdate(DOMonth.selectedIndex+1, DODay.selectedIndex+1))
        {
            if (DOMonth.selectedIndex+1 == 12)
            {
                DOMonth.selectedIndex = 0;
                DOYear.value = currentyear+1;
            }
            else
                DOMonth.selectedIndex++;

            DODay.selectedIndex = 0;
        }
    }

    if (!checkyear(PUMonth.selectedIndex+1))
        PUYear.value = currentyear+1;
    else
    {
        if (currentyear < parseInt(PUYear.value))
            PUYear.value = currentyear;
    }

    if (!checkyear(DOMonth.selectedIndex+1))
        DOYear.value = currentyear+1;
    else
    {
        if (currentyear < parseInt(DOYear.value))
            DOYear.value = currentyear;
    }        
}
Any ideas?





Similar Threads
Thread Thread Starter Forum Replies Last Post
'style' is null or not an object earhear Beginning PHP 0 December 4th, 2007 04:22 AM
null or not an object crmpicco Classic ASP Basics 0 July 4th, 2005 05:58 AM
null or not a object crmpicco Javascript How-To 5 March 22nd, 2005 10:48 AM
is null or not an object fosterjim Javascript How-To 1 January 24th, 2005 02:11 PM
document null or not an object Adam H-W Javascript 2 April 22nd, 2004 05:59 AM





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