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
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts


  •  

    Tags for this Thread

    Posting Permissions

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