Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 2nd, 2005, 11:42 PM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
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:
val[0]="one"
val[1]="four"
val[2]="sixty-five"
val[3]="ninety-eight"

now:
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.

TIA


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...

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

{
var boxes = document.f1.color.length
var nbxs = 0
    document.bgColor="white";
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"}
else
    {res = ""}

{document.bgColor=res};

}
  </script></head>
<body><br>
<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>
<br></form>
</body></html>
__________________
In a world of give and take, take all you can and you die with nothing.&nbsp;&nbsp;Give all you can and you&nbsp;&nbsp;die with honor.
Reply With Quote
  #2 (permalink)  
Old April 4th, 2005, 12:54 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Default

Hii Hatchingabrain!!
Try this code ,Hope it will help you

// file page1.htm

<body><br>
<form name="f1" action="page2.asp"><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>
<br>
<input type=submit value=submit>
</form>
</body></html>


and page2.asp is
 <%
   for i=1 to request("color").count
  Response.Write (request("color")(i) &"<br>" )
  next

%>


Cheers :)

vinod
Reply With Quote
  #3 (permalink)  
Old April 4th, 2005, 07:34 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That would be wonderful If I was actually mixing colors ;)

Its more like mixing ingrediants for a cake... Only I have 100 ingrediants to choose from...
(example)
the user can select any or all of the following: chocolate, vanilla, strawberry, orange, etc....on page 1.htm (their answer(s) are stored by cookie in the form page1value="1,4,60,98" or whatever was selected (for i=o;i<alldecheckboxes.length;i++);if (alldecheckboxes[i].checked) writemeacookie (page1value,alldecheckboxes[i])

on page 2.asp... each of the numbers reported by page 1 is put back into chocolate, vanilla, strawberry, whatever. and mixed: let us say page1value="0,1"
if (page1value = 0) myresponse="chocolate"
if (page1value = 0 && page1value = 1) myresponse="chocolate/vanilla swrill"
if (page1value = 1) myresponse="vanilla"

and myresponse needs to be stored as an array so that i can output
Your mixes are:

chocolate
chocolate/vanilla swrill
vanilla

I have 100 different checkboxes on page 1, that would translate into 150 different combinations
I DONOT want to have to create 150 if && combos! (if I can help it)
Reply With Quote
  #4 (permalink)  
Old April 6th, 2005, 05:37 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Default

Hii Hatchingabrain!!!
That's Great, I agree with you
Why don't we retrieve these values from the database,and make the form dynamically e.g
<% select item_name,item_code from the table
   populate the recordset%>
<% if recordset is not eof %>
  <% do while not recordset.eof%>
 <input name="color" value='<%=recordset("item_name")%>' type="checkbox"><%=recordset("item_name")%><br>

<% recordset.movenext
   loop%>

<% end if%>

now and page2.asp is
 <%
 strShow="You Have Selected"
   for i=1 to request("color").count
    strShow=strShow &" " & request("color")(i) &" "
  next

Response.Write (strShow)

%>

No need to use "If" statement :)
Hope this will help you

Cheers :)

vinod
Reply With Quote
  #5 (permalink)  
Old April 6th, 2005, 06:16 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My javascript is ok... My Html is better... My asp... well... ummm... I know how to get a cookie.... :D

1) do I put a ascii-type txt file in my web- folder and add my db values there? and that would be to populate the checkboxes on page1.asp, right?

2) how do I "mix" the results of page1? [time to get more detailed....shudder]
     1. Gidgets
     2. Widgets
     3. Midgets (no offense)
     4. Liggets
     5. Piggets
     6. Jigglets
      7. .... (etc...)

user selects 1,2,5,7
Page 2 outputs...

Doglets (from item 1)
Poglets (from item 2)
Fidgets (from item 5)
Moglets (from item 7)
Puglets (from combo of items 1 & 2)
Gigglets (from combo of items 1 & 5)
Pligets (from combo of items 1 & 7)
Ollets (from combo of items 2 & 5)
Limpets (from combo of items 2 & 7)
Muppets (from combo if items 5 & 7)

Any Help? :D

tia
Reply With Quote
  #6 (permalink)  
Old April 6th, 2005, 07:05 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Default

hii Hatchingabrain!!
I didn't get the point 2
2) how do I "mix" the results of page1? [time to get more detailed....shudder]

Can you explain it

Cheers :)

vinod
Reply With Quote
  #7 (permalink)  
Old April 6th, 2005, 07:10 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

2) how do I "mix" the results of page1? [time to get more detailed....shudder]
     1. Gidgets
     2. Widgets
     3. Midgets (no offense)
     4. Liggets
     5. Piggets
     6. Jigglets
      7. .... (etc...)

user selects 1,2,5,7

Page 2 outputs...

Doglets (because user selected item 1)
Poglets (because user selected item 2)
Fidgets (because user selected item 5)
Moglets (because user selected item 7)
Puglets (because user selected items 1 & 2)
Gigglets (because user selected items 1 & 5)
Pligets (because user selected items 1 & 7)
Ollets (because user selected items 2 & 5)
Limpets (because user selected items 2 & 7)
Muppets (because user selected items 5 & 7)

currently I have to:

if (item[i]="1")
  output ="Doglets"
if (item[i]="2")
  output = "Poglets"
if (item[i] = "1" && item[i] ="2")
  output ="Puglets"
etc....
of course... this doesn't actually work the way I want it to... because I cannot go through each number in the item list (ie: item=new Array "1,2,5,7") so i tried nesting do while passed on each value (I had written 150 if then statements and copy pasted them 150 times + so I could combine 1 + other values (if existed) then another do while for item 2 + other values....

I need another way :D

tia

(comprendo? I really hope so.. I'm not sure how else to explain it... )
Reply With Quote
  #8 (permalink)  
Old April 6th, 2005, 08:35 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Default

Hatchingabrain!!
Offcourse you can do this :)

***first.html page is ***

<body><br>
<form name="f1" action="chk1.asp"><br>
<h1>mix colors!</h1>
<h2><input name="color" value="red" type="checkbox">red<br>
 <input name="color" value="yellow" type="checkbox">yellow<br>
<input name="color" value="blue" type="checkbox">blue</h2><br>
<input name="color" value="red1" type="checkbox">red<br>
<input name="color" value="yellow1" type="checkbox">yellow<br>
<input name="color" value="blue1" type="checkbox">blue</h2><br>
<input name="color" value="red2" type="checkbox">red<br>
<input name="color" value="yellow2" type="checkbox">yellow<br>
<input name="color" value="blue2" type="checkbox">blue</h2>
<input type=submit value=submit>
</form>
</body></html>
and
***second.asp page is ***
<%

 for i=1 to request("color").count
  Response.Write (request("color")(i) &"<br>" )
 next
  for i=1 to request("color").count
  if(i<>request("color").count) then
  Response.Write (request("color")(i) &"&"&request("color")(i+1)&"<br>" )
  '//you can use your own array/values that you want to show
   end if
 next

%>
Hope this will help you

Cheers :)

vinod
Reply With Quote
  #9 (permalink)  
Old April 6th, 2005, 08:37 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Default

Please correct above code with
<form name="f1" action="second.asp">

Cheers :)

vinod
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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 2 April 4th, 2005 04:02 AM



All times are GMT -4. The time now is 05:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.