BSquared18
08-27-2003, 10:02 PM
I was provided the following code to generate a list of the TV channels for all the interest boxes that are checked off.
Is there a way to alter the code so that the entire list is sorted in alphabetical order? (I figured out how to sort them alphabetically within each interest group--all the movie channels for example--but not for all the groups combined together when more than one box is checked off.)
Also, as the code stands now, the items for adjacent interest groups run together without a comma between them. Is there a way to have the comma occur between adjacent interest groups even when the whole list is sorted alphabetically?
The first of these two improvements has a higher priority if only one or the other is possible.
The code is:
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script>
movieArr = new Array ("TCM","HBO","Starz","Cinemax")
newsArr = new Array ("Fox News","Headline News","CNN","ABC News")
sportsArr = new Array("ESPN","ESPN2","Fox Sports","CBS Sports")
childrensArr = new Array("Disney")
function showChannels(){
allInterests = document.myForm.interest
channels = ""
for (x=0; x<allInterests.length; x++){
if (allInterests[x].checked){
channels += eval(allInterests[x].value + "Arr")
}
}
alert(channels)
}
</script>
<form name="myForm">
<input type=checkbox name="interest" value="movie">movies
<input type=checkbox name="interest" value="news">news
<input type=checkbox name="interest" value="sports">sports
<input type=checkbox name="interest" value="childrens">childrens
<input type=button onClick="showChannels()" value="Get Channels">
</form>
</body>
</html>
Thanks!
Bill B.
Is there a way to alter the code so that the entire list is sorted in alphabetical order? (I figured out how to sort them alphabetically within each interest group--all the movie channels for example--but not for all the groups combined together when more than one box is checked off.)
Also, as the code stands now, the items for adjacent interest groups run together without a comma between them. Is there a way to have the comma occur between adjacent interest groups even when the whole list is sorted alphabetically?
The first of these two improvements has a higher priority if only one or the other is possible.
The code is:
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script>
movieArr = new Array ("TCM","HBO","Starz","Cinemax")
newsArr = new Array ("Fox News","Headline News","CNN","ABC News")
sportsArr = new Array("ESPN","ESPN2","Fox Sports","CBS Sports")
childrensArr = new Array("Disney")
function showChannels(){
allInterests = document.myForm.interest
channels = ""
for (x=0; x<allInterests.length; x++){
if (allInterests[x].checked){
channels += eval(allInterests[x].value + "Arr")
}
}
alert(channels)
}
</script>
<form name="myForm">
<input type=checkbox name="interest" value="movie">movies
<input type=checkbox name="interest" value="news">news
<input type=checkbox name="interest" value="sports">sports
<input type=checkbox name="interest" value="childrens">childrens
<input type=button onClick="showChannels()" value="Get Channels">
</form>
</body>
</html>
Thanks!
Bill B.