Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 2nd, 2005, 02:07 AM
Authorized User
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default mixing results of checkboxes

I have 100 checkboxes on page1.htm... the user selects any number of them and the results are transfered by cookie to page2.asp the results are in the format {formresult="1,4,65,98"}
I can remove the commas and assign each number to a array'd value...
{val= new Array("one","two","three","four","five",...(etc... )}
where as my output is:

I would like to be able to mix the values of the array so that if 1 and 4 are selected then item A is displayed
if 65 and 98 are selected then item b is displayed etc...

without having to write a billion if && then statements for each possible condition.


In a world of give and take, take all you can and you die with nothing.  Give all you can and you  die with honor.
Old April 2nd, 2005, 02:13 AM
Authorized User
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts

Currently I have a BASIC BASIC example of what I want (and don't want for a 100 checkboxes....) and you don't have to tell me I put in too many {} and ;;; all over the place... welcome to the world of netscape's javascript console... :D

  <title>color change demo</title>
  <script language="JavaScript">
function startme ()

var boxes = document.f1.color.length
var nbxs = 0
for (i=0; i<boxes; i++)
  {if (document.f1.color[i].checked)
        {nbxs++} }

if (nbxs == 0)
    {res = "white"}
else if (nbxs == 3)
    {res = "black"}
else if (nbxs == 1 && document.f1.color[0].checked)
    {res = "red"}
else if (nbxs == 1 && document.f1.color[1].checked)
    {res = "yellow"}
else if (nbxs == 1 && document.f1.color[2].checked)
    {res = "blue"}
else if (document.f1.color[0].checked && document.f1.color[1].checked)
    {res = "Orange"}
else if (document.f1.color[0].checked && document.f1.color[2].checked)
    {res = "Purple"}
else if (document.f1.color[1].checked && document.f1.color[2].checked)
    {res = "Green"}
    {res = ""}


<form name="f1" onclick="startme()" enctype="text/plain"><br>
<h1>mix colors!</h1>
<h2><input name="color" value="red" type="checkbox">red<br>
<br><input name="color" value="yellow" type="checkbox">yellow<br>
<br><input name="color" value="blue" type="checkbox">blue</h2><br>
Old April 4th, 2005, 04:02 AM
Friend of Wrox
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919

Please find the answer at

Cheers :)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
Mixing C and C# in a project? rotgut C# 2005 7 March 26th, 2007 07:05 AM
Mixing PHP and Javascript nmjnmj Pro PHP 4 December 9th, 2006 01:31 AM
Session Id mixing jejedp VS.NET 2002/2003 0 January 4th, 2006 07:54 PM
mixing results of checkboxes Hatchingabrain Javascript How-To 8 April 6th, 2005 08:37 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.