Solved

Visibility of Dynamic Drop Down List

Posted on 2006-10-24
1
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

729 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