faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 10 people (70%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

how to script which option in a select drop-down should be selected?

Feb 3rd, 2005 04:42
jsWalter, carsten dfgb,


// {{{ selectOption() 
    // Select a single option 
    function selectOption ( $objSelect, $intOptionIndex ) 
    { 
        // If $objFocusList is a string, convert to Object Reference 
        // Then see if Object Reference exists 
        if ( ( typeof ( $objSelect ) ) == 'string' ) 
            $objSelect = document.getElementById($objSelect); 
        // Do we have a list to deal with? 
        if ( ( $objSelect ) && ( $intOptionIndex >= 0 ) ) 
        { 
            // Move focus and Select Item 
            $objSelect.focus(); 
            $objSelect.options[$intOptionIndex].selected = true; 
        } 
    }; 
// }}} 
This is part of a larger collection of functions and methods I've been 
putting together for years. 
Walter