View Single Post
Old 08-13-2011, 03:23 PM   PM User | #1
chineerat
New to the CF scene

 
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
chineerat is an unknown quantity at this point
Dropdown menu error. Unable to get property 'options'

Hi!
I have the following javascript and accompanying html but the i keep getting the error:
Unable to get value of the property 'options': object is null or undefined
pointing to this line of the code
" $thisSelectedValue = $formField.options[ $formField.selectedIndex ].value;"
Can someone help me please...
thanks in advance.

Javascript
Code:
 <script type="text/javascript">
  
$allValues = new Array();
$allValues[0] = 'Choose One';
$allValues[1] = 'A1';
$allValues[2] = 'A2';
$allValues[3] = 'A3';
$allValues[4] = 'A4';
$allValues[5] = 'A5';
			
			
            function stripDupelicateValues(inElementId)
{
    // get current list of all selected values
    $selectedValues = new Array();

    for( $position in $allValues )
    {
        if( $position != 0 )
        {

            $formField = eval( 'document.crewchange.emp_' + $position );

            // preserve our selected values
            $thisSelectedValue = $formField.options[ $formField.selectedIndex ].value;
            $selectedValues[$thisSelectedValue] = true;
        }
    }


    for( $position in $allValues )
    {
        if( $position != 0 )
        {

            $formField = eval( 'document.crewchange.emp_' + $position );

            // preserve our selected values
            $thisSelectedValue = $formField.options[ $formField.selectedIndex ].value;

            // wipe out the previous choices
            $formField.options.length = 0;

            // create default option
            $formField.options[0] = new Option( $allValues[0], 0 );

            for( $optionValue in $allValues )
            {
                // add each of our non selected values
                if( $selectedValues[$optionValue] != true )
                {
                    $formField.options[$formField.options.length] = new Option( $allValues[$optionValue], $optionValue );
                }
                // create the option for our selected value
                else if( $thisSelectedValue == $optionValue )
                {
                    $index = $formField.options.length;

                    if( $optionValue != 0 )
                    {
                        $formField.options[$index] = new Option( $allValues[$optionValue], $optionValue );
                        $formField.options[$index].selected = true;
                    }
                }

            }
        }
    }
}


        </script>
Html
Code:
<form action="cc2.php" method="post"  name="cc">
<select name='emp[]' id='emp_1' onChange='stripDupelicateValues(this.id)'>
<option>Choose One</option>
<option value='1'>A1</option>
<option value='2'>A2</option>
<option value='3'>A3</option>
<option value='4'>A4</option>
<option value='5'>A5</option>
</select>
</form>
Error Msg
Code:
Message: Unable to get value of the property 'options': object is null or undefined
chineerat is offline   Reply With Quote