Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String manipulation and category building.

Status
Not open for further replies.

seanybravo

IS-IT--Management
Joined
Sep 24, 2003
Messages
89
Location
GB
String manipulation and category building.

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=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;><!--

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=&quot;firstexample&quot; onsubmit=&quot;return(False);&quot;>
<table border=&quot;1&quot; bgcolor=&quot;beige&quot; align=&quot;center&quot;>
<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=&quot;Algodata Infosystems&quot;>Algodata Infosystems</option>
<option value=&quot;0877&quot;>Binnet & Hardley</option>
<option value=&quot;1622&quot;>Five Lakes Publishing</option>
<option value=&quot;9901&quot;>GGG&G</option>
<option value=&quot;9999&quot;>Lucerne Publishing</option>
<option value=&quot;0736&quot;>New Moon Books</option>
<option value=&quot;1756&quot;>Ramona Publishers</option>
<option value=&quot;9952&quot;>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=&quot;text/JavaScript&quot;>
//Arrays for menus
if (!assocArray) var assocArray = new Object();
assocArray[&quot;list1=0736&quot;] = new Array(
&quot;PS7777&quot;,&quot;Emotional Security: A New Algorithm&quot;,
&quot;PS2091&quot;,&quot;Is Anger the Enemy?&quot;,
&quot;PS2106&quot;,&quot;Life Without Fear&quot;,
&quot;PS3333&quot;,&quot;Prolonged Data Deprivation: Four Case Studies&quot;,
&quot;BU2075&quot;,&quot;You Can Combat Computer Stress!&quot;,
&quot;EOF&quot;);
assocArray[&quot;list1=0877&quot;] = new Array(
&quot;PS1372&quot;,&quot;Computer Phobic AND Non-Phobic Individuals: Behavior Variations&quot;,
&quot;TC4203&quot;,&quot;Fifty Years in Buckingham Palace Kitchens&quot;,
&quot;TC3218&quot;,&quot;Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean&quot;,
&quot;MC2222&quot;,&quot;Silicon Valley Gastronomic Treats&quot;,
&quot;TC7777&quot;,&quot;Sushi, Anyone?&quot;,
&quot;MC3021&quot;,&quot;The Gourmet Microwave&quot;,
&quot;MC3026&quot;,&quot;The Psychology of Computer Cooking&quot;,
&quot;EOF&quot;);
assocArray[&quot;list1=Algodata Infosystems&quot;] = new Array(
&quot;PC1035&quot;,&quot;But Is It User Friendly?&quot;,
&quot;BU1111&quot;,&quot;Cooking with Computers: Surreptitious Balance Sheets&quot;,
&quot;PC9999&quot;,&quot;Net Etiquette&quot;,
&quot;PC8888&quot;,&quot;Secrets of Silicon Valley&quot;,
&quot;BU7832&quot;,&quot;Straight Talk About Computers&quot;,
&quot;BU1032&quot;,&quot;The Busy Executive's Database Guide&quot;,
&quot;EOF&quot;);
</script>
</td>
</tr>
</table>
</form>
</body>
 
Can you repost after unchecking &quot;Process TGML&quot; or by enclosing your code in
Code:
tags?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
as requested reposted with unchecking &quot;Process TGML&quot;

String manipulation and category building.

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 &quot;| &quot;. (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=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;><!--

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=&quot;firstexample&quot; onsubmit=&quot;return(False);&quot;>
<table border=&quot;1&quot; bgcolor=&quot;beige&quot; align=&quot;center&quot;>
<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=&quot;Algodata Infosystems&quot;>Algodata Infosystems</option>
<option value=&quot;0877&quot;>Binnet & Hardley</option>
<option value=&quot;1622&quot;>Five Lakes Publishing</option>
<option value=&quot;9901&quot;>GGG&G</option>
<option value=&quot;9999&quot;>Lucerne Publishing</option>
<option value=&quot;0736&quot;>New Moon Books</option>
<option value=&quot;1756&quot;>Ramona Publishers</option>
<option value=&quot;9952&quot;>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=&quot;text/JavaScript&quot;>
//Arrays for menus
if (!assocArray) var assocArray = new Object();
assocArray[&quot;list1=0736&quot;] = new Array(
&quot;PS7777&quot;,&quot;Emotional Security: A New Algorithm&quot;,
&quot;PS2091&quot;,&quot;Is Anger the Enemy?&quot;,
&quot;PS2106&quot;,&quot;Life Without Fear&quot;,
&quot;PS3333&quot;,&quot;Prolonged Data Deprivation: Four Case Studies&quot;,
&quot;BU2075&quot;,&quot;You Can Combat Computer Stress!&quot;,
&quot;EOF&quot;);
assocArray[&quot;list1=0877&quot;] = new Array(
&quot;PS1372&quot;,&quot;Computer Phobic AND Non-Phobic Individuals: Behavior Variations&quot;,
&quot;TC4203&quot;,&quot;Fifty Years in Buckingham Palace Kitchens&quot;,
&quot;TC3218&quot;,&quot;Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean&quot;,
&quot;MC2222&quot;,&quot;Silicon Valley Gastronomic Treats&quot;,
&quot;TC7777&quot;,&quot;Sushi, Anyone?&quot;,
&quot;MC3021&quot;,&quot;The Gourmet Microwave&quot;,
&quot;MC3026&quot;,&quot;The Psychology of Computer Cooking&quot;,
&quot;EOF&quot;);
assocArray[&quot;list1=Algodata Infosystems&quot;] = new Array(
&quot;PC1035&quot;,&quot;But Is It User Friendly?&quot;,
&quot;BU1111&quot;,&quot;Cooking with Computers: Surreptitious Balance Sheets&quot;,
&quot;PC9999&quot;,&quot;Net Etiquette&quot;,
&quot;PC8888&quot;,&quot;Secrets of Silicon Valley&quot;,
&quot;BU7832&quot;,&quot;Straight Talk About Computers&quot;,
&quot;BU1032&quot;,&quot;The Busy Executive's Database Guide&quot;,
&quot;EOF&quot;);
</script>
</td>
</tr>
</table>
</form>
</body>
 
<script language=&quot;vbs&quot;>
dim stringArray
stringArray = Array (&quot;Agriculture, Forestry & Fishing[1]|&quot;,&quot;Agriculture, Forestry & Fishing[1]|Growing of crops; market gardening; horticulture&quot;,&quot;Agriculture, Forestry & Fishing[1]|Farming of animals&quot;,&quot;Agriculture, Forestry & Fishing[1]|Mixed farming&quot;,&quot;Agriculture, Forestry & Fishing[1]|Agricultural and animal husbandry service activities, except veterinary activities&quot;,&quot;Agriculture, Forestry & Fishing[1]|Hunting, trapping and game propagation and related service activities&quot;,&quot;Agriculture, Forestry & Fishing[1]|Forestry, logging and related service activities&quot;,&quot;Agriculture, Forestry & Fishing[1]|Fishing, operation of fish hatcheries and fish farms; service activities incidental to fishing&quot;,&quot;Energy and manufacture of mineral products[2]|&quot;,&quot;Energy and manufacture of mineral products[2]|Extraction of minerals, oils and natural gas, and related service activities&quot;,&quot;Energy and manufacture of mineral products[2]|Glass and glass products&quot;)

for x = 0 to Ubound(stringArray)
thisPart = split(stringArray(x),&quot;|&quot;)
if thisPart(1) = &quot;&quot; then
'add option to list1
list1 = list1 & &quot;<option value='&quot; & thisPart(0) & &quot;'>&quot; & thisPart(0)
else
if arrayString <> &quot;&quot; then
arrayString = left(arrayString, len(arrayString) - 1)
end if
arrayString = arrayString & vbcrlf & &quot;assocArray['list1=&quot; & thisPart(0) & &quot;'] = new Array(&quot;
do while thisPart(1) <> &quot;&quot;
arrayString = arrayString & &quot;'&quot; & thisPart(1) & &quot;','&quot; & thisPart(1) & &quot;,&quot;
if x < uBound(stringArray) then
x = x + 1
thisPart = split(stringArray(x),&quot;|&quot;)
else
exit do
end if
loop
if x < uBound(stringArray) then
x = x - 1
else
exit for
end if
end if
next

arrayString = left(arrayString, len(arrayString) - 1)
alert(list1)
alert(arrayString)
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
mwolf00

Fantastic! The code seams to do what I want, I will have to play about with it a bit more first though. Just a quick question sometimes I have up to three categories ie

Agriculture, Forestry & Fishing[1]|Farming of animals|Cows

Is the code you wrote for me flexible enough to handle that or will it need modifying?

You have done wonders for my stress levels.

Many thanks for your time.

Sean

 
I wrote that as a fix for the javascript functions that you ar working with, it isn't capable of another jump without some modification. Sorry that I don't have time right now to make the modification...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
mwolf00

Further Info

The category list that you wrote the code for can vary as I want to reuse the code with different category lists. They will be set out the same only that they may only be a category on its own or a category with sub categories as per the example.

The code you wrote for me is great and I am currently researching how it works.

What parts need modifying?

Thanks

Sean
 
In order to add another subset, you will need to create another set of arrays. In javascript, I would normally create my arrays like this...

listArray = new Array(&quot;Field1&quot;,&quot;Field2&quot;,&quot;Field3&quot;)

Field1Array = new Array(&quot;subCat1&quot;,&quot;subCat2&quot;)
Field2Array = new Array(&quot;subCat3&quot;,&quot;subCat5&quot;)
Field3Array = new Array(&quot;subCat4&quot;,&quot;subCat6&quot;)

subCat1Array = new Array(&quot;value1&quot;,&quot;value12&quot;)
subCat2Array = new Array(&quot;value2&quot;,&quot;value11&quot;)
subCat3Array = new Array(&quot;value3&quot;,&quot;value10&quot;)
subCat4Array = new Array(&quot;value4&quot;,&quot;value9&quot;)
subCat5Array = new Array(&quot;value5&quot;,&quot;value8&quot;)
subCat6Array = new Array(&quot;value6&quot;,&quot;value7&quot;)

Then you'd need your function to eval() the array values sent. Using this scenario, you could make a very flexible program. However, you won't be able to have spaces in the value names. I usually use the primary key to identify the arrays...




Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top