Solved

Visibility of Dynamic Drop Down List

Posted on 2006-10-24
1
227 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

773 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