String manipulation and category building.

S

Sean Williams

I have been working in this problem for weeks and I was determined to sort
it myself however I feel I need guidance to proceed forward.

What I am trying to produce is some asp code that can split categories and
group from a text string that is delimited by a "| ". (see string examples
below). I have managed to find some javascript that will handle the
different levels of categories without having to keep refreshing the page.
So I want the asp code to split the categories in the javascript array's
(see java code below) and be flexible enough to handle different numbers of
sub categories as they can vary.

Any guidance or examples would be appreciated.

Thanks

Sean

---------------

String examples

Agriculture, Forestry & Fishing[1]|
Agriculture, Forestry & Fishing[1]|Growing of crops; market gardening;
horticulture
Agriculture, Forestry & Fishing[1]|Farming of animals
Agriculture, Forestry & Fishing[1]|Mixed farming
Agriculture, Forestry & Fishing[1]|Agricultural and animal husbandry service
activities, except veterinary activities
Agriculture, Forestry & Fishing[1]|Hunting, trapping and game propagation
and related service activities
Agriculture, Forestry & Fishing[1]|Forestry, logging and related service
activities
Agriculture, Forestry & Fishing[1]|Fishing, operation of fish hatcheries and
fish farms; service activities incidental to fishing
Energy and manufacture of mineral products[2]|
Energy and manufacture of mineral products[2]|Extraction of minerals, oils
and natural gas, and related service activities
Energy and manufacture of mineral products[2]|Glass and glass products

---------------

Java code

<script language="JavaScript" type="text/JavaScript"><!--

function comboItemSelected(oList1,oList2){
if (oList2!=null){
clearComboOrList(oList2);
if (oList1.selectedIndex == -1){
oList2.options[oList2.options.length] = new Option('Please make a selection
from the list', '');
} else {
fillCombobox(oList2, oList1.name + '=' +
oList1.options[oList1.selectedIndex].value);
}}}

function clearComboOrList(oList){
for (var i = oList.options.length - 1; i >= 0; i--){
oList.options = null;
}
oList.selectedIndex = -1;
if (oList.onchange) oList.onchange();
}

function fillCombobox(oList, vValue){
if (vValue != '') {
if (assocArray[vValue]){
oList.options[0] = new Option('Please make a selection', '');
var arrX = assocArray[vValue];
for (var i = 0; i < arrX.length; i = i + 2){
if (arrX != 'EOF') oList.options[oList.options.length] = new
Option(arrX[i + 1], arrX);
}
if (oList.options.length == 1){
oList.selectedIndex=0;
if (oList.onchange) oList.onchange();
}
} else {
oList.options[0] = new Option('None found', '');
}}}
//--></script>

<body>
<p>
And this second example shows a pair of single-entry &quot;combo&quot;
pulldowns filled
with the same data:
</p>
<form name="firstexample" onsubmit="return(False);">
<table border="1" bgcolor="beige" align="center">
<tr>Publishers Titles</tr>

<tr><td>
<select name='list1' size='1' style='width:360;'
onchange='comboItemSelected(this,this.form.list2);'>
<option>Please make a selection</option>
<option value="Algodata Infosystems">Algodata Infosystems</option>
<option value="0877">Binnet & Hardley</option>
<option value="1622">Five Lakes Publishing</option>
<option value="9901">GGG&G</option>
<option value="9999">Lucerne Publishing</option>
<option value="0736">New Moon Books</option>
<option value="1756">Ramona Publishers</option>
<option value="9952">Scootney Books</option>
</select>

</td><td><p>
<select name='list2' size='1' style='width:360;'>
<option>Please select an item from the preceding list</option>
</select>

<script language='JavaScript' type="text/JavaScript">
//Arrays for menus
if (!assocArray) var assocArray = new Object();
assocArray["list1=0736"] = new Array(
"PS7777","Emotional Security: A New Algorithm",
"PS2091","Is Anger the Enemy?",
"PS2106","Life Without Fear",
"PS3333","Prolonged Data Deprivation: Four Case Studies",
"BU2075","You Can Combat Computer Stress!",
"EOF");
assocArray["list1=0877"] = new Array(
"PS1372","Computer Phobic AND Non-Phobic Individuals: Behavior
Variations",
"TC4203","Fifty Years in Buckingham Palace Kitchens",
"TC3218","Onions, Leeks, and Garlic: Cooking Secrets of the
Mediterranean",
"MC2222","Silicon Valley Gastronomic Treats",
"TC7777","Sushi, Anyone?",
"MC3021","The Gourmet Microwave",
"MC3026","The Psychology of Computer Cooking",
"EOF");
assocArray["list1=Algodata Infosystems"] = new Array(
"PC1035","But Is It User Friendly?",
"BU1111","Cooking with Computers: Surreptitious Balance Sheets",
"PC9999","Net Etiquette",
"PC8888","Secrets of Silicon Valley",
"BU7832","Straight Talk About Computers",
"BU1032","The Busy Executive's Database Guide",
"EOF");
</script>
</td>
</tr>
</table>
</form>
</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,104
Messages
2,570,646
Members
47,248
Latest member
Angelita78

Latest Threads

Top