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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing session-variables with Checkboxes 1

Status
Not open for further replies.

IL

Programmer
Jan 7, 2002
15
SE
Hi again,

There are six checkboxes on page1.asp, I can make three
choices out these six and pass it on to page2 for
validation. If there are more than three choices made the
user is brought back to page1.asp. The checkboxes still checked from the first round.

IL

 
Hi
the Q is exactly that, how do you get the checkboxes
to still be checked when you return to the first page.
Or maybe stated differently, how do you submit boolean
values along with session objects and pass them back and
forth between pages.

IL
 
Here you go... =)

<% If Request.QueryString(&quot;action&quot;) = &quot;verify&quot; then

Dim ChkValue, tmpChkValue, ChkCount

tmpChkValue = Request.Form(&quot;check&quot;)

ChkValue = Replace(tmpChkValue, &quot;, &quot;, &quot;,&quot;) '# take out spaces

ChkValue = Split(ChkValue, &quot;,&quot;)

For Each Check in ChkValue
ChkCount = ChkCount + 1 '# Count checked boxes...
Next

If ChkCount > 3 Then
Response.Write &quot;You checked more then 3 boxes please fix it and try again!&quot;
Else
Response.Redirect &quot;page2.asp&quot;
End If

End if

%>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;page1.asp?action=verify&quot;>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;1&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;1&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;2&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;2&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;3&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;3&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;4&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;4&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;5&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;5&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;6&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;6&quot;) > 0 then Response.Write &quot;checked&quot; %>>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
 
Hi Snowboardr

I have som code that works just like yours.
I tried your code, but the checkmarks in the checkboxes
are not retained on return to page 1.
There is a very simple way to find out how many checkboxes
have been checked:
let's give the checkboxes the name &quot;interest&quot; then follows
items = request.form(&quot;interest&quot;).count
this line will give you the number of checkboxes checked
and store that number in the variable items.
Very simple.
BUT

I have page1.asp and page2.asp.
On page1 I have one checkbox like the follwoing
...
<form name=&quot;form1&quot; action=&quot;page2.asp&quot;....aso..>
<input type=&quot;checkbox&quot; name=&quot;interest&quot; value=&quot;Flowers&quot;
<%if InStr(interest,&quot;Flowers&quot;) then Response.write(&quot;checked&quot;)>
<input type=&quot;submit&quot; value=&quot;submit&quot;
</form>
...

page2.asp
...
<%session(&quot;interest&quot; = Request.Form(&quot;interest&quot;)

Hello
You have made the following choice:
<%=Session(&quot;interest&quot;)%><br>
<A HREF=&quot;page1.asp?interest=Request.Form(&quot;interest&quot;)>Go Back</A>
....

So, on page one tick the checkbox and submit.
on page2 you will se somthing like this
Hello, you have made the following choice: Flowers

Go Back
....

you click - Go Back - and when you get back to page1
you find the checkbox is empty. This is NOT what I want,
I want the checkmark to remain in the checkbox.
I have tried all sorts of variables and if-constructs and so far nothing works.
Do I have to submit a whole bunch of checkboxes as hidden to page2 in order to be able to get the value back again to page1....if so,,,,how to do it...?

IL

IL

 
The way I did it works fine, and it DOES keep the checks checked...

Thats the job of..

<% If InStr(Request.Form(&quot;check&quot;), &quot;1&quot;) > 0 then Response.Write &quot;checked&quot; %>

-----------------------

For one, in your code this is not right..

<A HREF=&quot;page1.asp?interest=Request.Form(&quot;interest&quot;)>

it would be more like

<A HREF=&quot;page1.asp?interest=<%=Request.Form(&quot;interest&quot;)%>>


This is also not correct..

<%session(&quot;interest&quot; = Request.Form(&quot;interest&quot;)

you forgot the &quot;)&quot;

<%session(&quot;interest&quot;) = Request.Form(&quot;interest&quot;)


Try my code on one page and name the asp page page1.asp it works fine for me...
 
Hi Snowboardr

Have tried putting your code on two different pages.
The first part on page1.asp and the part of the code beginning with <bodycolor.....
on page2.asp.
I still cannot get this to work.
Btw the errors that you pointed out in my code here on the post are only typing errors here, my code which I have on a different computer, does not have these errors.

Anyway I modified my own code slightly, and I got as far as
to having a checkmark already filled out in the checkbox and this way it is carried back and forth, but that is not
the solution. The checkboxes have to be empty from the beginning and I make the choice by putting the checkmark in the box.

Is there something missing in the code that you have supplied here on the post.?
What happens when you run your code ?

IL

 
sorry to butt in, in the middle of this, BUT I wanted to add that snowboardr's code is working correct both on IIS and off my server. not sure what else you want!?

How excatly are you incorpurating his code into your page.
you do have a whole lot of typos up there as pointed out and if they are not corrected they may be causing the problems we are not seeing. [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
IL, do this.. open up notepad and paste this in there...

Save it as page1.asp

Code:
<% If Request.QueryString(&quot;action&quot;) = &quot;verify&quot; then

        Dim ChkValue, tmpChkValue, ChkCount
        
        tmpChkValue = Request.Form(&quot;check&quot;)
            
        ChkValue = Replace(tmpChkValue, &quot;, &quot;, &quot;,&quot;)  '# take out spaces
        
        ChkValue = Split(ChkValue, &quot;,&quot;)
        
        For Each Check in ChkValue
        ChkCount = ChkCount + 1  '# Count checked boxes...
        Next
        
        If ChkCount > 3 Then
        Response.Write &quot;You checked more then 3 boxes please fix it and try again!&quot;
            Else
        Response.Write &quot;Ok the right number of checkboxes are checked, here is where we add the response.Redirect to your page2.asp page&quot;
        End If
        
    End if

%>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;page1.asp?action=verify&quot;>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;1&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;1&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;2&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;2&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;3&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;3&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;4&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;4&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;5&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;5&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;6&quot; <% If InStr(Request.Form(&quot;check&quot;), &quot;6&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
[/b]


After you do that goto the page on your server

[URL unfurl="true"]http://localhost/page1.asp[/URL]

This code works, but for some reason you are not doing something right. You will get it, hang in there.

-Jason
 
Hey IL, don't put that code on to different pages, just put it on a single page, because you want it to verify it on the same page as the form, then goto your page2.asp.
 
Hi again

first of all - thank you all for your help.

1. the typing mistakes pointed out by you, are not in my
code. The mistakes were made only here on the post as pointed out to you. ...Trip eh Trim

2. No, I do not want Snowboardr's code on 1 page because as I've pointed out from the beginning, the checkbox is on one page, with the value. say the checkbox is interest and the value is flowers. I should make the choice &quot;flowers&quot; by putting a checkmark in the checkbox next to it and THEN
send this over to another serverpage for validation. nb the checkbox must not be pre-checked, you should put the mark there yourself by clicking the box.
All this works beautifully. BUT if there are some requirements not met when the code is verified, then I should go back to page one to remake my choices. NOW this is the SNAG, when I return to page 1 the checkmark that I put there the first time is no longer there. IT SHOULD NOT be EMPTY, the checkmark needs to still be there. This is what this whole piece of code and my question is all about.

actually when you have a checkbox you give it a name, call it Checkbox you then give the checkbox a value and you can also specify if the checkbox should be already checked by adding &quot;checked&quot; after the &quot;value&quot; string, ....here Flowers. Now both these values have to be sent back and forth. If you make the box pre-checked then there are no problems. BUT that is not what we want, we don't want any pre-checked choices, we want to make them ourself.

3. I have tried Snowboardr's code. Run the code, the checkboxes are empty on start, check them and send it all off to page 2 for validation...nothing...and return to page 1, nothing.?? No checkmarks.

4.this is why I asked what happens when YOU run the code.

5. to &quot;onpnt&quot; I use Snowboardr's code just as it is here, to be able to run it and see how it works OK, and my reason for writing to this post again is the fact that the code does not work accoring to my observations and according to my needs, this is why I'm asking what happens when you run the code. It would be much more helpful if you would answer that question at this point.
Maybe we don't have the same idea about what the problem is here and how to solve it.

IL
 
Well here we go..

I put them on my server as well as wrote a second version which uses two pages..

(the first one)
(the one I just wrote)

check.asp
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<a href=&quot;page1.asp&quot;>QueryString Verify method</a><br>
<a href=&quot;check.asp&quot;>2 page verifying method</a><br>


<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;check2.asp&quot;>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;1|flower1&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;1&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;2|flower2&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;2&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;3|flower3&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;3&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;4|flower4&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;4&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;5|flower5&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;5&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;6|flower6&quot; <% If InStr(Session(&quot;chkvalue&quot;), &quot;6&quot;) > 0 then Response.Write &quot;checked&quot; %>>
  <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
</body>
</html>


check2.asp
Code:
<% 

		Dim ChkValue, tmpChkValue, ChkCount, SplitChkValue, AryItems(6), ItemsChecked
		
				


		tmpChkValue = Request.Form(&quot;check&quot;)
		Session(&quot;chkvalue&quot;) = tmpChkValue
		ChkValue = Replace(tmpChkValue, &quot;, &quot;, &quot;,&quot;)  '# take out spaces
		
		ChkValue = Split(ChkValue, &quot;,&quot;)
		

		
		AryItems(1) = &quot;flower1&quot;
		AryItems(2) = &quot;flower2&quot;
		AryItems(3) = &quot;flower3&quot;
		AryItems(4) = &quot;flower4&quot;	
		AryItems(5) = &quot;flower5&quot;
		AryItems(6) = &quot;flower6&quot;


		For Each Check in ChkValue
							
			chkcount = chkcount + 1  '# count chks
				
				If instr(tmpChkValue,AryItems(chkcount)) > 1 then  '# If the word flowerX appears in the form values add to list
				
					
						ItemsChecked =  ItemsChecked & &quot;, &quot; & AryItems(chkcount) 
					         
					
				

			End if
			
		Next
					If Left(ItemsChecked, 1) = &quot;,&quot; then
						ItemsChecked = Right(ItemsChecked, Len(ItemsChecked) - 1)   '# Remove the very left comma
					End if



		
		If ChkCount > 3 Then
			Response.Write &quot;You chose &quot; & ItemsChecked & &quot; <b>you have selected to many checks</b> please go back and select less then 3 checkboxes&quot;
			

			Else
		Response.write &quot;You have checked &quot; & ItemsChecked & &quot; you may proceed!&quot;
		End If
		
	



%>
<a href=&quot;check.asp&quot;>go back</a>
 
Hey its adding spaces to my URL, so you have to take the end spaces out for it to work...
 
you're sure putting a lot of effort in snowboardr.
[star]
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Yea I know onpnt, but im curious to see why this script isnt working for him and works fine for me and you. Thanks for the star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top