Solved

Visibility of Dynamic Drop Down List

Posted on 2006-10-24
1
225 Views
Last Modified: 2011-09-20
I need to code for a dependant dynamic drop down list ...  ;)

What I would like to do is, based on user selection from the first Category box, to either display further options or hide the SubCat drop down list.  

document.drop_list.SubCat.disabled=true;  --works just fine to disable but it does not hide from screen.  Any comments would be aprpeciated!!  Below is the code.

Thanks!


========================================

<!--dyn_dropdownlist.js-->

function fillCategory(){
 // this function is used to fill the category list on load


addOption(document.drop_list.Category, "City/County/State", "City/County/State", "");
addOption(document.drop_list.Category, "Contractor", "Contractor", "");
addOption(document.drop_list.Category, "Federal Military", "Federal Military", "");
addOption(document.drop_list.Category, "Golf Course", "Golf Course", "");
addOption(document.drop_list.Category, "Nursery or Tree Growing", "Nursery or Tree Growing", "");
addOption(document.drop_list.Category, "Rental Center", "Rental Center", "");
addOption(document.drop_list.Category, "Utility Company", "Utility Company", "");


}

function SelectSubCat(){
// ON selection of category this function will work

removeAllOptions(document.drop_list.SubCat);
addOption(document.drop_list.SubCat, "", "SubCat", "");



if(document.drop_list.Category.value == 'City/County/State'){
addOption(document.drop_list.SubCat,"Electric", "Electric");
addOption(document.drop_list.SubCat,"Highway Department", "Highway Department");
addOption(document.drop_list.SubCat,"Landfill", "Landfill");
addOption(document.drop_list.SubCat,"Streets and Sanitation", "Streets and Sanitation");
addOption(document.drop_list.SubCat,"Parks and Recreation", "Parks and Recreation");
addOption(document.drop_list.SubCat,"Water/Sewer", "Water/Sewer");
addOption(document.drop_list.SubCat,"Other", "Other");



}

if(document.drop_list.Category.value == 'Contractor'){
addOption(document.drop_list.SubCat,"Boring", "Boring");
addOption(document.drop_list.SubCat,"CATV", "CATV");
addOption(document.drop_list.SubCat,"Electric", "Electric");
addOption(document.drop_list.SubCat,"General Construction", "General Construction");
addOption(document.drop_list.SubCat,"General Trenching", "General Trenching");
addOption(document.drop_list.SubCat,"Golf Course Construction", "Golf Course Construction");
addOption(document.drop_list.SubCat,"Irrigation", "Irrigation");
addOption(document.drop_list.SubCat,"Land Cleaning", "Land Cleaning");
addOption(document.drop_list.SubCat,"Landscaping", "Landscaping");
addOption(document.drop_list.SubCat,"Pipeline", "Pipeline");
addOption(document.drop_list.SubCat,"Roads", "Roads");
addOption(document.drop_list.SubCat,"Telephone", "Telephone");
addOption(document.drop_list.SubCat,"Tree Service", "Tree Service");
addOption(document.drop_list.SubCat,"Waste Processing/Landfill", "Waste Processing/Landfill");
addOption(document.drop_list.SubCat,"Water/Sewer", "Water/Sewer");
addOption(document.drop_list.SubCat,"Other", "Other");

}

if(document.drop_list.Category.value == 'Federal Military'){
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
}

if(document.drop_list.Category.value == 'Golf Course'){
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
}

if(document.drop_list.Category.value == 'Nursery or Tree Growing'){
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
addOption(document.drop_list.SubCat," ", " ");
}

if(document.drop_list.Category.value == 'Rental Center'){
//addOption(document.drop_list.SubCat," ", " ");
//addOption(document.drop_list.SubCat," ", " ");
//addOption(document.drop_list.SubCat," ", " ");
//document.drop_list.SubCat.disabled=true;
document.drop_list.SubCat.display="none";
}

if(document.drop_list.Category.value == 'Utility Company'){
addOption(document.drop_list.SubCat,"Boring", "Boring");
addOption(document.drop_list.SubCat,"CATV", "CATV");
addOption(document.drop_list.SubCat,"Electric", "Electric");
addOption(document.drop_list.SubCat,"General Construction", "General Construction");
addOption(document.drop_list.SubCat,"General Trenching", "General Trenching");
addOption(document.drop_list.SubCat,"Golf Course Construction", "Golf Course Construction");
addOption(document.drop_list.SubCat,"Irrigation", "Irrigation");
addOption(document.drop_list.SubCat,"Land Cleaning", "Land Cleaning");
addOption(document.drop_list.SubCat,"Landscaping", "Landscaping");
addOption(document.drop_list.SubCat,"Pipeline", "Pipeline");
addOption(document.drop_list.SubCat,"Roads", "Roads");
addOption(document.drop_list.SubCat,"Telephone", "Telephone");
addOption(document.drop_list.SubCat,"Tree Service", "Tree Service");
addOption(document.drop_list.SubCat,"Waste Processing/Landfill", "Waste Processing/Landfill");
addOption(document.drop_list.SubCat,"Water/Sewer", "Water/Sewer");
addOption(document.drop_list.SubCat,"Other", "Other");
}




}
//////////////////

function removeAllOptions(selectbox)
{
      var i;
      for(i=selectbox.options.length-1;i>=0;i--)
      {
            //selectbox.options.remove(i);
            selectbox.remove(i);
      }
}


function addOption(selectbox, value, text )
{
      var optn = document.createElement("OPTION");
      optn.text = text;
      optn.value = value;

      selectbox.options.add(optn);
}


========================================


<!--HTML CODE-->



<html>
<head>
<title>dynamic drop down list</title>
<script language="javascript" src="dyn_dropdownlist.js"></script>
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();">

<FORM name="drop_list" action="" method="POST" >
Customer Type:            
<SELECT  NAME="Category" onChange="SelectSubCat();" >
<Option value="">Category</option>
<!--<OPTION VALUE="City/County/State"> City/County/State
<OPTION VALUE="Contractor"> Contractor
<OPTION VALUE="Federal Military"> Federal Military
<OPTION VALUE="Golf Course"> Golf Course
<OPTION VALUE="Nursery or Tree Growing"> Nursery or Tree Growing
<OPTION VALUE="Rental Center"> Rental Center
<OPTION VALUE="Utility Company"> Utility Company-->
</SELECT>&nbsp;

<SELECT id="SubCat" NAME="SubCat">
<Option value="">SubCat</option>

</SELECT>
</form>

</body>

</html>
0
Comment
Question by:Chip
1 Comment
 
LVL 5

Accepted Solution

by:
daohailam earned 50 total points
ID: 17797370
to hide:
  document.drop_list.style.display = 'none';
  document.drop_list.style.visibility = 'hidden';

to show:
  document.drop_list.style.display = '';
  document.drop_list.style.visibility = 'visible';
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mutually exclusive checkbox in a gridview 18 42
Compare site how does it work 4 52
C3-->D3 Line Chart 4 19
Asp.net mvc foreach 3 6
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now