Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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 January 20th, 2005, 01:47 AM
Registered User
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to avoid long IF statements

Hello All!

can someone tell me whether there are any alternatives to using IF and ELSEIF statements to record user inputs in a checkbox. I've four checkboxes and i just want to grab the ones that the user has checked.
For ex,
IF checkbox1.checked AND checkbox2.checked Then
DO SUMTHING
END IF

Right now, i've a long IF and elseif statements to do the job.
i see that the using case and select wont work with checkbox.checked!
is there any other ways? TIA

 
Old January 20th, 2005, 02:23 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Name them all the same (yes just like radio buttons) Then when the user submits the form a commer delimited string (usually id's) will be posted to the destination page. These values will be all the checked boxes, if none were checked the form variable wil be equal to an empty string.

Wind is your friend
Matt
 
Old January 20th, 2005, 09:30 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I had to do this, I would have coded as under

Let chk_1,chk_2,chk_3,chk_4 be the elements

Dim str_check
str_check = ""
if request(chk_1) <> "" then
   str_check = str_check & "1"
else
   str_check = str_check & "0"
end if

if request(chk_2) <> "" then
   str_check = str_check & "1"
else
   str_check = str_check & "0"
end if

if request(chk_3) <> "" then
   str_check = str_check & "1"
else
   str_check = str_check & "0"
end if

if request(chk_4) <> "" then
   str_check = str_check & "1"
else
   str_check = str_check & "0"
end if

Now the str_chk will have a 4 characters in it (eg .. 1001,1100 etc..)

So I can directly use switch statements (switch is always better than using a lot of if statements)
Select Case str_chk
   Case "0000"
      statements . . .
   Case "0001"
      statements ....
...
...
    case "1111"
      statements ....

End Select

   Hope this would be better ....









Similar Threads
Thread Thread Starter Forum Replies Last Post
Long Long int to bin walid C# 0 January 23rd, 2007 12:47 PM
Use of long long int jvanp C# 2005 2 September 20th, 2006 06:07 PM
Use of long long int jvanp C++ Programming 7 October 3rd, 2004 01:59 PM
string to "long long" without using atoll sarraju C++ Programming 2 August 4th, 2004 07:19 AM
Modifying long text in a long field sajsal Classic ASP Databases 1 February 20th, 2004 12:36 PM





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