473,378 Members | 1,527 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,378 software developers and data experts.

how to retrieve CheckBox value using GET Method ?

If I have

<form action="process.asp" method="get" name="form1">

....
....
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

</form>

If I check all, when submit, I will get in URL string

http://....?... &sports=Cricket&sports=Swimming&sports=Football

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
How cna I know how many "sports" have been selected ?
Assume that all must having same checkbox name, and must use GET method,
instead of POST

Thanks.

regards,
Magix
Aug 21 '08 #1
9 7340
magix wrote on 21 aug 2008 in microsoft.public.inetserver.asp.general:
If I have

<form action="process.asp" method="get" name="form1">

...
...
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

</form>

If I check all, when submit, I will get in URL string

http://....?... &sports=Cricket&sports=Swimming&sports=Football

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
I think, but please test first:

request.querystring("sports")(0)
request.querystring("sports")(1)
How cna I know how many "sports" have been selected ?
request.querystring("sports").length
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 21 '08 #2
Evertjan. wrote:
>How cna I know how many "sports" have been selected ?

request.querystring("sports").length
More like .Count:
http://msdn.microsoft.com/en-us/library/ms524784.aspx
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 21 '08 #3
Dave Anderson wrote on 21 aug 2008 in
microsoft.public.inetserver.asp.general:
Evertjan. wrote:
>>How cna I know how many "sports" have been selected ?

request.querystring("sports").length

More like .Count:
http://msdn.microsoft.com/en-us/library/ms524784.aspx
Yesss!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 21 '08 #4
"magix" wrote:
If I have
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
How cna I know how many "sports" have been selected ?
Other answers right, but more complex than needed.

Just do this:

<%
....
sports = Trim( Request("sports") ) ' do not need to say Request.QueryString
If sports = "" Then
... no sports selected ...
Else
sports = Split( sports, ", " ) ' that is COMMA-SPACE and *not* just comma
Response.Write "You selected " & UBound(sports)+1 " sports."
End If
....
%>

This works fine so long as none of the VALUE= values for the checkboxes
contain COMMA-SPACE.

But you should be sure you really need to do the SPLIT, first. You may be
able to do many SQL queries without bothering to get the individual choices.

Aug 21 '08 #5
Old Pedant wrote:
"magix" wrote:
>If I have
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
How cna I know how many "sports" have been selected ?

Other answers right, but more complex than needed.

Just do this:

<%
...
sports = Trim( Request("sports") ) ' do not need to say
Request.QueryString
Perhaps not, but I would suggest you do so.
I'm surprised a pedant would advise someone to be less that precise! :-)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 21 '08 #6


"Bob Barrows [MVP]" wrote:
Old Pedant wrote:
sports = Trim( Request("sports") ) ' do not need to say
Request.QueryString

Perhaps not, but I would suggest you do so.
I'm surprised a pedant would advise someone to be less that precise! :-)
LOL! But it *IS* precise...if you know what you are doing.

http://msdn.microsoft.com/en-us/libr...48(VS.85).aspx

Since QueryString is searched first, then
Request("foo")
is equivalent to
Request.QueryString("foo")
with the proviso that the latter actually exists.

Now, pedantically, if for some reason the querystring value does not exist
then the search process will indeed try to find that name in all the other
collections. But unless your code has created a "sports" key/value pair in
Request.Form (that is, via POST) or Cookies, that's not an issue.

Anyway, the reason I tended to use just Request was simple: During
development and debug, I'd use METHOD=GET in my <FORM>s so I could see in the
URL what I was passing. Then, once it was working and debugged, I'd change
to METHOD=POST but wouldn't have to change my VBS code.

A hack, but I think a reasonable one.

Anyway, I'll bet in this case there's no reason for him to know how many
were selected and/or separate them. I'll bet that if he constructed the SQL
efficiently he'd just need to do something such as
sql = " ... WHERE sport IN ('" & Replace(Request("sports"),", ","','")
& "') "
or similar.


Aug 21 '08 #7
"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:D7**********************************@microsof t.com...
"magix" wrote:
If I have
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
How cna I know how many "sports" have been selected ?

Other answers right, but more complex than needed.
I'm sorry perhaps I'm miss reading you but you seem to be saying the other
answers are more complex than needed and yours below is simpler??
Just do this:

<%
...
sports = Trim( Request("sports") ) ' do not need to say
Request.QueryString

Bob was more gentle, I would say that this is not a good practice at all.
Always use either .QueryString or .Form. I've seen the short cut above
cause too many headaches especially when a page was using GET then switches
to POST.

If sports = "" Then
... no sports selected ...
Else
sports = Split( sports, ", " ) ' that is COMMA-SPACE and *not* just
comma
Response.Write "You selected " & UBound(sports)+1 " sports."
End If
...
%>

This works fine so long as none of the VALUE= values for the checkboxes
contain COMMA-SPACE.
Yikes. Is that 'less complex'? Have you tested it? Does it seem to you to
match the querystring structure seen in the OP?
But you should be sure you really need to do the SPLIT, first. You may be
able to do many SQL queries without bothering to get the individual
choices.
>
Thats an interesting assertion. Can you achieve that without creating a SQL
statement using string concatenation which I'm sure you would agree would be
a bad thing?
--
Anthony Jones - MVP ASP/ASP.NET
Aug 22 '08 #8
"magix" <ma***@asia.comwrote in message
news:48**********@news.tm.net.my...
If I have

<form action="process.asp" method="get" name="form1">

...
...
<input TYPE=checkbox name=sports VALUE=Cricket>
<input TYPE=checkbox name=sports VALUE=Swimming>
<input TYPE=checkbox name=sports VALUE=Football>

</form>

If I check all, when submit, I will get in URL string

http://....?... &sports=Cricket&sports=Swimming&sports=Football

So, in process.asp, how can I differentiate each of them with
request.querystring("sports)?
How cna I know how many "sports" have been selected ?
Assume that all must having same checkbox name, and must use GET method,
instead of POST
Why GET instead of POST? Do you deliberately want enable the possiblity
that a response can be delivered from the cache?

--
Anthony Jones - MVP ASP/ASP.NET
Aug 22 '08 #9
Old Pedant wrote:
Anyway, the reason I tended to use just Request was simple: During
development and debug, I'd use METHOD=GET in my <FORM>s so I could
see in the URL what I was passing. Then, once it was working and
debugged, I'd change to METHOD=POST but wouldn't have to change my
VBS code.
This seems to contradict your earlier argument that Request("foo") is the
same as Request.QueryString("foo") because QueryString is the first
collection searched.

If you change your form methods to POST, are you not introducing a
useless -- and potentially interfering -- search through the QueryString
collection for your post-development scripts?

A hack, but I think a reasonable one.
Well, that's one opinion.

We have solved countless problems by breaking people of this habit.
Likewise, default properties.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Aug 22 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
3
by: Amy Snyder | last post by:
For what I thought would be a very simple task is turning out to be very frustrating. I have been trying for a day now to extract checkbox values from my form and nothing is working. On my form...
1
by: Art | last post by:
Hi, I have a problem with checkbox value on the page connected to MS Access. Ms Access field is: Independent - Data Type: Yes/No My code is: <form name="form" method="post"...
1
by: Jerim79 | last post by:
I have a simple 3 page registration form. One form, one "data validation" script and one "insert into database" script. The customer bounces back and forth from the form to the verification script...
4
by: Matt | last post by:
I am no JavaScript guru so please bear with me and be as detailed as possible with your response. I thank you in advance. I have an ASP page that contains form elements. I also have an inline...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
2
by: palanidharma | last post by:
hi, i writing the code for selectd check box value deleted.but the code not working <?php include("conn.php"); $sel= mysql_select_db("sangoma"); //include("function.php"); ?>
2
by: JFKJr | last post by:
Hello everyone! I am a new beginner to ASP.NET, I have created two pages page1.aspx, page2.aspx and I am trying to pass course name value to page2.aspx from page1.aspx using the following URL: ...
1
by: Greg Eyres | last post by:
Apologies if this is a stupid question ... I'm new to this PHP world! I have got an html form that has checkboxes dynamically created from MySQL. I use an array to create the list of checkboxes. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.