Jump to content

[SOLVED] subcat box remains gray?


darkfreaks

Recommended Posts

how do i change it so when you select a category the sub category box below it is ungrey?

 


<SCRIPT language=javascript>

<!--

var blnIE;	//IE? for table highlighting etc...

var	strEmptyString;

var	strCatSelectedString;

var hexEnabled = "#ffffff";

var hexDisabled = "#dddddd";

var hexHighlightOn = "#FFB300";

var hexHighlightOff = "#ffffff";



//arrayLevel 0 for top level, 1 for next level down etc...

function populate(arrayLevel)

{

//get the value of the selected index (click)

strOptionValue = (docSelectorArray[arrayLevel].options[docSelectorArray[arrayLevel].selectedIndex].value);



//if value is 0 then is a spacer option - move their choice to the bottom option

if (strOptionValue == 0){



	if (docSelectorArray[arrayLevel].selectedIndex != 0){

		docSelectorArray[arrayLevel].selectedIndex	= docSelectorArray[arrayLevel].selectedIndex - 1;

		strOptionValue = (docSelectorArray[arrayLevel].options[docSelectorArray[arrayLevel].selectedIndex].value);

	}



	//if they have clicked in an empty table then dont do anything

	else {

		return;	

	}

}



//get the option text so we can see if we have a leaf or a branch (" >")

strOptionText = (docSelectorArray[arrayLevel].options[docSelectorArray[arrayLevel].selectedIndex].text);



//clear lower level select boxes------------------------------------------

//outerloop through select boxes, starting from the one below this clickf

for (i = arrayLevel+1; i < intLevels; i++){



	//inner loop through the number of items in select boxes

	for (j = docSelectorArray[i].length-2; j >= 0; j--){

		docSelectorArray[i].options[j] = null;

	}



	//keep box a consistent width

	docSelectorArray[i].options[0] = new Option(strEmptyString, "0");



	//disable and unhighlight

	if (blnIE){

		docSelectorArray[i].style.background = hexDisabled;

		docTableArray[i].style.background = hexHighlightOff;

	}

	docSelectorArray[i].disabled = true;

	//docImageArray[i].src = docImageSrcOffArray[i];



}



//need another branch (branch or top level)-------------------------------

if ((strOptionText.indexOf(" >") != -1)){



	//clear any value from the category box

	category.value = "";



	//disable the next button

	submitButton.disabled = true;



	//get the next array and the number of options in it

	intNextArray = docSelectorArray[arrayLevel].options[docSelectorArray[arrayLevel].selectedIndex].value;



	//populate the next level if they didn't choose the "Select a Category" option

	if (intNextArray != 0){				



		//enable next arrayLevel

		docSelectorArray[arrayLevel+1].disabled = false;



		//IE only

		if (blnIE){

			docSelectorArray[arrayLevel+1].style.background = hexEnabled;		//color of next select box is now enabled

			docTableArray[arrayLevel].style.background = hexHighlightOff;		//this table now unhighlighted			

			docTableArray[arrayLevel+1].style.background = hexHighlightOn;		//next table now highlighted			

			docTableArray[intTableSubmit].style.background = hexHighlightOff;		//Next button table unhighlighted			

		}



		//get the number of options for the next level and populate the options

		intNumberOptions = c[intNextArray].length;



		//populate array with options

		for (i = 0; i < intNumberOptions; i++){

			docSelectorArray[arrayLevel+1].options[i] = c[intNextArray][i];

		}



		//put a new option at the end of the list so that we have a consistent size on the box

		docSelectorArray[arrayLevel+1].options[intNumberOptions] = new Option(strEmptyString, "0");



		//unhighlight any previous selection

		if (docSelectorArray[arrayLevel+1].selectedIndex != -1) {

			docSelectorArray[arrayLevel+1].selectedIndex = -1;

		}

	}

}



//have reached a leaf, populate the others with end text-------------------------------------------------

else {

	//get the option for this selection		

	if (strOptionValue != 0) {

		category.value = strOptionValue;

	}



	//outerloop through select boxes, starting from the one below this click

	for (i = arrayLevel+1; i < intLevels; i++){

		//populate with end text

		docSelectorArray[i].options[0] = new Option(strCatSelectedString, "0");

	}



	//enable and hightlight submit button

	submitButton.disabled = false;	



		//IE only

		if (blnIE){

			docTableArray[arrayLevel].style.background = hexHighlightOff;

			docTableArray[intTableSubmit].style.background = hexHighlightOn;		

		}		

}

}



//arrayLevel 0 for top level, 1 for next level down etc...

function prePopulate(mCat)

{



//check mCat is sane

if (mCat.length < 5) return;					//must be at least 2 levels

if (mCat.length % 5 != 0) return;				//each mCat is 5 chars long

if (mCat.charAt(mCat.length - 1) != '-') return;//last char of last mCat is '-'



var mCatArray = mCat.split('-');	//this is now an array of strings, mCatArray[0] = '0011' etc...

var intMcat							//integer from string mcat '0011' -> 11 etc...

var strOptionText					//text of option selected to see if we are a leaf or not

var intNextArray					//next array down from the one we are currently working on

var intNumberOptions				//number of options for the next level







//outer loop down through the levels

for (intArrayLevel = 0; intArrayLevel < (mCatArray.length - 1); intArrayLevel++){



	//set integer version of mCat

	intMcat = parseInt(mCatArray[intArrayLevel],10);



	//inner loop - find the matching mCat and set it

	for (intArrayOption = 0; intArrayOption < docSelectorArray[intArrayLevel].length; intArrayOption++){



		//found a match

		if (docSelectorArray[intArrayLevel].options[intArrayOption].value == intMcat){



			//so select the index and get the text

			docSelectorArray[intArrayLevel].selectedIndex = intArrayOption;

			strOptionText = (docSelectorArray[intArrayLevel].options[intArrayOption].text);



			//unset the selected image and table highlight for the current level

			//docImageArray[intArrayLevel].src = docImageSrcOffArray[intArrayLevel];

			if (blnIE){

				docTableArray[intArrayLevel].style.background = hexHighlightOff;

			}



			//do we need another branch or have we reached the leaf?

			//need another branch (branch or top level)-------------------------------

			if (strOptionText.indexOf(" >") != -1){



				//set the selected image and table highlight for this next level

				//docImageArray[intArrayLevel+1].src = docImageSrcOnArray[intArrayLevel+1];

				if (blnIE){

					docTableArray[intArrayLevel+1].style.background = hexHighlightOn;	

					docSelectorArray[intArrayLevel+1].style.background = hexEnabled;

				}



				//enable this next level

				docSelectorArray[intArrayLevel+1].disabled = false;



				//get the next array

				intNextArray = docSelectorArray[intArrayLevel].options[docSelectorArray[intArrayLevel].selectedIndex].value;



				//get the number of options for the next level and populate the options

				intNumberOptions = c[intNextArray].length;

				for (i = 0; i < intNumberOptions; i++){

					docSelectorArray[intArrayLevel+1].options[i] = c[intNextArray][i];

				}



				//put a new option at the end of the list so that we have a consistent size on the box

				docSelectorArray[intArrayLevel+1].options[intNumberOptions] = new Option(strEmptyString, "0");



				//if we are 1 level from the end then check and select the next option if appropriate

				if (intArrayLevel == 2){



					//get last mCat

					intMcat = parseInt(mCatArray[intArrayLevel+1],10);



					//loop through the last category and find the appropriate category

					for (i = 0; i < intNumberOptions; i++){

						if (docSelectorArray[intArrayLevel+1].options[i].value == intMcat){



							//set the selected index and populate the category box

							docSelectorArray[intArrayLevel+1].selectedIndex = i;

							category.value = intMcat;



							//unset the selected image and table highlight for the current level

							//docImageArray[intArrayLevel+1].src = docImageSrcOffArray[intArrayLevel];



							//enable and highlight submit button

							submitButton.disabled = false;	



							if (blnIE){

								docTableArray[intArrayLevel+1].style.background = hexHighlightOff;								

								docTableArray[intTableSubmit].style.background = hexHighlightOn;									

							}



							//break now to stop looping through the final box

							break;

						}

					}

					//found the final cat so stop here

					return;

				}

			}



			//have reached a leaf, populate the others with end text------------------

			else {

				//populate the category box

				category.value = docSelectorArray[intArrayLevel].options[intArrayOption].value;



				//outerloop through select boxes, starting from the one above this click

				for (i = intArrayLevel+1; i < intLevels; i++){

					//populate with end text

					docSelectorArray[i].options[0] = new Option(strCatSelectedString, "0");

					docSelectorArray[i].disabled = true;		

				}



				//enable and highlight submit button

				submitButton.disabled = false;	

				if (blnIE){					

					docTableArray[intTableSubmit].style.background = hexHighlightOn;

				}

			}

			//break out of this loop, as we have found a match and do not need to continue checking

			break;

		}

	}

}

}



// -->

</SCRIPT>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.