Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
0
0
CA
Visit site
I know this must seem a simple problem .. but its driving me crazy! I have one checkbox, and I want to see whether or not its been checked. On the form with the checkbox, I coded it as:

<input type=checkbox name=Favs value=Favorites>

And on the next ASP page, I have:

Favs = request(&quot;Favs&quot;)

if Favs = &quot;Favorites&quot; then
session(&quot;Favs&quot;) = &quot;Yes&quot;
elseif Favs = &quot;&quot; then
session(&quot;Favs&quot;) = &quot;No&quot;
end if

But, I never have a value for Favs, even when its checked. What am I missing?? Thanks for any help. :eek:)


[sig][/sig]
 
several issues. the major one is that you need

Favs = Request.Form(&quot;Favs&quot;) not Favs = request(&quot;Favs&quot;)

consider the following...

default.html -
Code:
<html>
<body>
<form id=frmForm method=&quot;POST&quot; action=&quot;check.asp&quot;>
 Favorites? <input type=checkbox id=favs name=favs>
 <input type=Submit>
</form>
</body>
</html>

check.asp -
Code:
<%
 Dim favs
 favs=UCASE(Request.Form(&quot;favs&quot;))
 
 if favs=&quot;ON&quot; then
  response.write &quot;You want favorites&quot;
 else
  response.write &quot;You don't want favorites&quot;
 end if
%>

Hope this helps,
Rob


[sig][/sig]
 
Thanks Rob .. I did make the changes that you suggested, and when I print the value of Favs, it always says &quot;NO&quot; .. not sure why this is .. I will include my code below:

default.html

<form id=frmForm method=&quot;POST&quot; action=&quot;SubCategory.asp&quot;><BR> Show only my favorites
<input type=checkbox id=favs name=favs><BR> 


SubCategory.asp

Favs = UCASE(request.form(&quot;Favs&quot;))

if Favs = &quot;ON&quot; then
session(&quot;Favs&quot;) = &quot;Yes&quot;
else
session(&quot;Favs&quot;) = &quot;No&quot;
end if
Favs = session(&quot;Favs&quot;)
response.write &quot;FAVS=&quot; & Favs

I tried adding a write statement immediately after the Favs= UCASE(request.form(&quot;Favs&quot;)) line, to check value, and it printed nothing, except Favs=

I guess I am still missing something here :eek:(






[sig][/sig]
 
Almost there,

default.html -
Code:
<form id=frmForm method=&quot;POST&quot; action=&quot;SubCategory.asp&quot;><BR> Show only my favorites
<input type=checkbox id=favs name=favs><BR>
<input type=submit value=&quot;submit&quot;>
</form>

SubCategory.asp -
<%
Favs = UCASE(request.form(&quot;Favs&quot;))

if Favs = &quot;ON&quot; then
session(&quot;Favs&quot;) = &quot;Yes&quot;
else
session(&quot;Favs&quot;) = &quot;No&quot;
end if
Favs = session(&quot;Favs&quot;)
response.write &quot;FAVS=&quot; & Favs
%>
[/code]

Good luck,
Rob [sig][/sig]
 
ohhh I see what you are getting at .. but I don't want a submit button, the user click the checkbox, then clicks on a category name, which is a link to another page .. I guess I need to pass the parameter of the checkbox with the link .. will try that, and thanks again!

allyeric [sig][/sig]
 
Getting ever closer to your goal. Here is one way...

default.html -
Code:
<html>
<script language=&quot;javascript&quot;>
 function fnSubmit(strCategory){
  document.forms.frmForm.category.value=strCategory;
  window.submit;
 }
</script>
<body>
<form name=frmForm id=frmForm method=&quot;POST&quot; action=&quot;SubCategory.asp&quot;><br> Show only my favorites
<input type=checkbox id=favs name=favs><br><br>
<input type=hidden id=category name=category value=&quot;Category 1&quot;>
Categories...<br>
<input type=image src=&quot;c:\img1.gif&quot; alt=&quot;Category 1&quot; onClick=&quot;fnSubmit('Category 1')&quot;><br><br>
<input type=image src=&quot;c:\img2.gif&quot; alt=&quot;Category 2&quot; onClick=&quot;fnSubmit('Category 2')&quot;>
</form>
</body>
</html>

SubCategory.asp -
Code:
<html>
<body>
<%
Favs = UCASE(request.form(&quot;favs&quot;))
Category = UCASE(request.form(&quot;category&quot;))

if Favs = &quot;ON&quot; then
  session(&quot;Favs&quot;) = &quot;Yes&quot;
else
  session(&quot;Favs&quot;) = &quot;No&quot;
end if
  Favs = session(&quot;Favs&quot;)
response.write &quot;FAVS= &quot; & Favs & &quot;<br>&quot;
response.write &quot;CATEGORY= &quot; & Category
%>
</body>
</html>

Later [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
Here's what you need to do:

1.Html ---
------------
<form name=&quot;test&quot; action=&quot;checkbox.asp&quot; method=&quot;post&quot;>
<input type=&quot;checkbox&quot; name=&quot;test1&quot; value=&quot;Vasia&quot;>
<a href=&quot;#&quot; onClick=&quot;javascript:document.test.submit();&quot;>Click to check</a>
</form>
----------------

2.In checkbox.asp it will be just:
dim test --- if you want
test = request(&quot;test&quot;)
response.write test ,
or simply:
response.write request(&quot;test&quot;)

 
guestg,

if you have more than 1 checkbox checked
will the
test = request(&quot;test&quot;)
have all the values separated by commas ?

paul.net
 
paul.net(visitor),
<code>
test=request(&quot;test&quot;) will contain string of as many values separated by commas ,as there are (checked) check boxes, provided they all have same name.
To access them individually one can use the following code:
item=request.form(&quot;test&quot;)(i) domain of 'i' being 1 to request.form(&quot;test&quot;).count .
Caution: if only one check box is checked then using the above notation gives error, as there is only one element is available with that name. one can access it the usual way. The above count property can be checked for 0,1,or more to find the correct way to access.
</code>
 
1.Html ---
------------
<form name=&quot;test&quot; action=&quot;checkbox.asp&quot; method=&quot;post&quot;>
<input type=&quot;checkbox&quot; name=&quot;test1&quot; value=&quot;Vasia&quot;>
<input type=&quot;checkbox&quot; name=&quot;test1&quot; value=&quot;Petia&quot;>
<input type=&quot;checkbox&quot; name=&quot;test1&quot; value=&quot;Kolia&quot;>
<a href=&quot;#&quot; onClick=&quot;javascript:document.test.submit();&quot;>Click to check</a>
</form>
----------------

2.In checkbox.asp it will be just:
dim test,i

for i = 1 to request.form(&quot;test1&quot;).count
test = request.form(&quot;test1&quot;)(i)
response.write test & &quot;,&quot;
next
 
Can you please help me out with this:-

First I am creating a dynamic check box like this:-
<%
response.Write(&quot;<input name=menuCheck&quot; & n+1 & &quot; type=checkbox id=menuCheck value=menucheckbox&quot; & n+1 & &quot; >&quot;)
rs1.movenext
n = n + 1

then I am doing this in the next ASP:-

For n = 0 to VarN
MenuCheckVal = UCASE(request.Form(&quot;menuCheck&quot; & n))
if MenuCheckVal = &quot;ON&quot; then
response.Write(&quot;ON&quot;)
else
response.Write(&quot;OFF&quot;)
end if
next

but it is displaying always OFF.

Can you tell me what is wrong?
 

>>> For n = 0 to VarN
>>> MenuCheckVal = UCASE(request.Form(&quot;menuCheck&quot; & n))
>>> if MenuCheckVal = &quot;ON&quot; then
>>> response.Write(&quot;ON&quot;)
>>> else
>>> response.Write(&quot;OFF&quot;)
>>> end if
>>> next

Try this:

For n = 0 to VarN
if (execute(&quot;menuCheckVal&quot;&i&&quot;=&quot;&UCASE(request.form(&quot;menuCheck&quot;)&n)))&&quot;=&quot;&quot;ON&quot;&quot;&quot; then
response.Write(&quot;ON&quot;)
else
response.Write(&quot;OFF&quot;)
end if
next 'n

in your example you will always get the last value as the variable you are setting will be overwritten with the latest value on every parse thru the loop - I am creating a variable menuCheckVal1, menuCheckVal2, menuCheckVal3 etc.

or you could just use:

For n = 0 to VarN
if UCASE(request.form(&quot;menuCheck&quot;&n))=&quot;ON&quot; then
response.Write(&quot;ON&quot;)
else
response.Write(&quot;OFF&quot;)
end if
next 'n

Either way, you will get a long list of on's or off's...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top