Click to See Complete Forum and Search --> : Interest Inventory Needs Refining


BSquared18
09-02-2003, 09:32 AM
Thanks to the generosity of a Javascript programmer, I was provided the script below to generate matches between TV channels and customer interests. It generates the list in alphabetical order. One problem, however, is that if a channel is included in two interest categories, the channel is repeated in the generated list for each inclusion. For instance, in the example below, "WAM" is in two different interest categories, so it appears twice in the generated list.

Is there a way to refine the code so that when channels are included in more than one interest category, the channel name appears only once in the generated list? So that, for example, WAM would appear just once.

If you can help, please edit the code below for the desired result.

Thanks!

Bill B.

<script>
moviesArr = new Array ("TCM,","HBO,","Starz,","Cinemax,","WAM,")
newsArr = new Array ("Fox News,","Headline News,","CNN,","ABC News,")
cartoonsArr = new Array("Boomerang,","Toon Disney,", "WAM,")

function showChannels(){
allInterests = document.myForm.interest
channels = ""
for (x=0; x<allInterests.length; x++){
if (allInterests[x].checked){
channels += eval(allInterests[x].value + "Arr")
}
}
finalResults = channels.split(",")
finalResults.sort()
alert(finalResults)
}
</script>
<br>
<form name="myForm">
<input type=checkbox name="interest" value="movies">Movies
<br>
<input type=checkbox name="interest" value="news">News
<br>
<input type=checkbox name="interest" value="cartoons">Cartoons
<br>
<br>

<input type=button onClick="showChannels()" value="Get Channels">
</form>