473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Multiple values from checkboxes

Hello all

I am very new to asp coding and i have a problem which i need help on.

Here is the code i've written so far.

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <%
  3. year1 = request.form("2007")
  4. year2 = request.form("2008")
  5. year3 = request.form("2009")
  6. year4 = request.form("2010")
  7.  
  8.     If year1 = "" AND year2 = "" AND year3 = "" AND year4 = "" then
  9.         endresult = "NO RESULT"
  10.     End If
  11.     If year1 = "2007" AND year2 = "" AND year3 = "" AND year4 = "" then
  12.         endresult = "2007"
  13.     End If
  14.     If year1 = "" AND year2 = "2008" AND year3 = "" AND year4 = "" then
  15.         endresult = "2008"
  16.     End If
  17.     If year1 = "" AND year2 = "" AND year3 = "2009" AND year4 = "" then
  18.         endresult = "2009"
  19.     End If
  20.     If year1 = "" AND year2 = "" AND year3 = "" AND year4 = "2010" then
  21.         endresult = "2010"
  22.     End If
  23.  
  24. Response.write endresult
  25. %>
  26. <form method="POST" action="checkbox.asp">
  27.     <p>
  28.     <input type="checkbox" name="2007" value="2007">2007 
  29.     <input type="checkbox" name="2008" value="2008">2008 
  30.     <input type="checkbox" name="2009" value="2009">2009 
  31.     <input type="checkbox" name="2010" value="2010">2010&nbsp; 
  32.     <input type="submit" value="Submit" name="B1"></p>
  33. </form>
  34. </body>
  35.  
What i'm trying to do is when the user ticks the box(s) the value goes into endresult but with a twist!!

If i do a single tick then endresult would = that value.

But if i do multiple ticks then i want to find the lowest value then inclued a " - " and find the highest value i.e 2007 - 2009, 2007 - 2010 and so on.

I've been able to work out single ticks which i have done here. But when if comes to finding a value morethan 1 it becomes a bit more complicated for me at a beginners level.

I do hope some will be able to help me with this.

Thanks in advance.

Rickky
Jul 1 '10 #1
2 1973
I've managed to work this problem out. Here is the code and it might help another newbie like me!!!

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <%
  3. yearselected = request.form("year")
  4.  
  5. If (Len(yearselected)) >= 10 then
  6. Response.write (Left(yearselected,4)) & " - " & (Right(yearselected,4))
  7. Else
  8. Response.write yearselected
  9. End If
  10.  
  11. %>
  12. <form method="POST" action="checkboxnew.asp">
  13.     <p>
  14.     <input type="checkbox" name="year" value="2007">2007 
  15.     <input type="checkbox" name="year" value="2008">2008 
  16.     <input type="checkbox" name="year" value="2009">2009 
  17.     <input type="checkbox" name="year" value="2010">2010&nbsp; 
  18.     <input type="submit" value="Submit" name="B1"></p>
  19. </form>
  20. </body>
  21.  
Jul 1 '10 #2
1. I do not recommend using numbers as a name of form's items. In your case you they have names as "2007". Instead of <input type="checkbox" name="2007" value="2007"> you may use something like <input type="checkbox" name="a2007" value="2007">

2. Try this code, I I get your what you want:


<%
HighestValue = ""
LovestValue = ""

For intCount = 2007 to 2010
If LovestValue = "" then LovestValue = request.form(cStr(intCount))
next

For intCount = 2010 to 2007 step -1
If HighestValue = "" then HighestValue = request.form(cStr(intCount))
next

if HighestValue = LovestValue then
endresult = HighestValue
else
endresult = LovestValue & " - " & HighestValue
end if

response.write(endresult)
%>
Jul 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Henri Schomaecker | last post by:
Hi folks, does php 5 have a problem with html select lists which allow to choose multiple items? Whatever I tried I just can't get another or more than the last item selected in the list....
6
by: Emmett Power | last post by:
Hi, I have a form on a web page with a number of radio buttons bound to the same field. Is it possible to set up the form so that users can select more than one radio button to submit multiple...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
5
by: Homer Simpson | last post by:
Hi All, I'm trying to write a method where I pass three arguments and the method returns six values. All the values will be doubles. First, is it possible to get multiple values returned by a...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
1
by: wendy184 | last post by:
I'm used to using 2007 which allows multiple values in the lookup wizard, this helps hugely with my queries as the database i'm building has information on one parent who may have up to 5 kids. ...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
2
by: satyanarayan sahoo | last post by:
Can we write a method which returns multiple values?
0
by: Maric Michaud | last post by:
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit : Disctionaries are hash tables with a unique key and constant time lookup. What you want could be implemented as a complex data...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.