Modifying SELECT Options (IE4+) : Option Select ComboBox : Form Control : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Java
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Form Control » Option Select ComboBox 
Modifying SELECT Options (IE4+)

/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

Publisher: John Wiley & Sons CopyRight 2001
ISBN: 0764533428

*/

<HTML>
<HEAD>
<TITLE>Changing Options On The Fly</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// flag to reload page for older NNs
var isPreNN6 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion<= 4)
// initialize color list arrays
plainList = new Array(6)
hardList = new Array(6)
plainList[0"cyan"
hardList[0"#00FFFF"
plainList[1"magenta"
hardList[1"#FF00FF"
plainList[2"yellow"
hardList[2"#FFFF00"
plainList[3"lightgoldenrodyellow"
hardList[3"#FAFAD2"
plainList[4"salmon"
hardList[4"#FA8072"
plainList[5"dodgerblue"
hardList[5"#1E90FF"
// change color language set
function setLang(which) {
    var listObj = document.forms[0].colors
    var newOpt
    // filter out old IE browsers
    if (listObj.type) {
        // find out if it's 3 or 6 entries
        var listLength = listObj.length
        // save selected index
        var currSelected = listObj.selectedIndex
        // replace individual existing entries
        for (var i = 0; i < listLength; i++) {
            newOpt = document.createElement("OPTION")
            newOpt.text = (which == "plain"? plainList[i: hardList[i]
            listObj.options.remove(i)
            listObj.options.add(newOpt, i)
        }
        listObj.selectedIndex = currSelected
    }
}
// create entirely new options list
function setCount(choice) {
    var listObj = document.forms[0].colors
    var newOpt
    // filter out old browsers
    if (listObj.type) {
        // get language setting
        var lang = (document.forms[0].geekLevel[0].checked"plain" "hard"
        // empty options from list
        while (listObj.options.length) {
            listObj.options.remove(0)
        }
        // create new option object for each entry
        for (var i = 0; i < choice.value; i++) {
            newOpt = document.createElement("OPTION")
            newOpt.text = (lang == "plain"? plainList[i: hardList[i]
            listObj.options.add(newOpt)
        }
        listObj.options[0].selected = true
    }
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Flying Select Options</H1>
<FORM>
Choose a palette size:
<INPUT TYPE="radio" NAME="paletteSize" VALUE=
onClick="setCount(this)" CHECKED>Three
<INPUT TYPE="radio" NAME="paletteSize" VALUE=
onClick="setCount(this)">Six
<P>
Choose geek level:
<INPUT TYPE="radio" NAME="geekLevel" VALUE="" 
onClick="setLang('plain')" CHECKED>Plain-language
<INPUT TYPE="radio" NAME="geekLevel" VALUE="" 
onClick="setLang('hard')">Gimme hex-triplets!
<P>
Select a color:
<SELECT NAME="colors">
    <OPTION SELECTED>cyan
    <OPTION>magenta
    <OPTION>yellow
</SELECT>
</FORM>
</BODY>
</HTML>





           
       
Related examples in the same category
1. Set select to multiple selected
2. Options in select
3. Option label
4. Option default Selected Example
5. Option selected Index Example
6. Option selected
7. Is Select a select-multiple
8. 'index' Example
9. 'value' Example
10. Add an option to select
11. 'text' Example
12. Option selected index
13. Auto Linked Option Listbox without button
14. Change background
15. Changing Select Element Content (two Combobox)
16. Drop-down Redirect - No Submit button
17. Drop-down Redirect - Submit
18. Dropdown list (combobox) in a form
19. dropdown list (combobox) in form 2
20. Disable or enable an option
21. Disable and enable a dropdown list (combobox)
22. Return the name of the form that contains dropdown list (combobox)
23. Number of options in the dropdown list(Combobox)
24. Change the size of a dropdown list (ComboBox)
25. Select multiple options in a dropdown list (option)
26. Return the selected option as text in option
27. Return the selected option as a number
28. Change the option text
29. Remove an option from a dropdown list (combobox)
30. Methods and Properties of the Select Object
31. Properties of the Option Object
32.  Using the Location object to change another frame's URL
33. Using a Summary Form to Support Local Processing
34. Navigating with a SELECT Object
35. Using the selectedIndex Property
36.  Modifying OPTGROUP Element Labels
37. Using the options[index].text Property
38.  Using the options[index].value Property
39. Triggering a Color Change from a Pop-Up Menu
40. Modifying SELECT Options
41. Modifying SELECT Options (NN6+)
42. Selecting an Option Using JavaScript
43. Linked ComboBox (option) Country =- province
44. ComboBox set value to TextField
45. Menu(Option) Generator
46. URL Option ComboBox
47. Show Selected Option items
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.