Subject: selectedIndex is NULL or not an Object
Posted By: lewdogg Post Date: 9/28/2006 9:29:20 AM
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...


<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?

Go to topic 20116

Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156
Return to index page 155
Return to index page 154
Return to index page 153