Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Old 08-13-2011, 04:58 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
Find answer here:

http://forums.devshed.com/javascript...ns-840933.html
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
dropdown, form, javascript, select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:24 PM.


Advertisement
Log in to turn off these ads.