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

Write cookie depending on selected radio button.

Status
Not open for further replies.

JeroenDortmans

Technical User
Aug 7, 2001
56
NL
I want to make a form with 2 radio buttons and 1 submit button. When the user clicks the submit button a cookie must be written. The contents of this cookie differs corresponding the selected radio button. After that the page must redirect corresponding the selected radio button. When no radio button is selected, a message must be written. Here my code:

<%
dim PC_or_CAD
PC_or_CAD=Request.Form(&quot;PC_or_CAD&quot;)
%>

<form action=&quot;Write_cookie.asp&quot; method=&quot;post&quot;>
<p><font color=&quot;#FF0000&quot;><b>Select one of these options. After that click on
&quot;Submit information&quot;. This will store the information so you won't be
bothered with this question again.<br>
</b></font><input type=&quot;radio&quot; name=&quot;Radio_button&quot;
<%if PC_or_CAD = &quot;PC&quot; then Response.Write(&quot;checked&quot;)%>
value=&quot;PC&quot;> You use a PC<br>
<input type=&quot;radio&quot; name=&quot;Radio_button&quot;
<%if PC_or_CAD = &quot;CAD&quot; then Response.Write(&quot;checked&quot;)%>
value=&quot;CAD&quot;> You use a CAD system
<br>
<input type=&quot;submit&quot; value=&quot;Submit information&quot;>
</form>
<%
if PC_or_CAD=&quot;PC&quot; then
Response.Cookies(&quot;PC_or_CAD&quot;)=&quot;You use a PC.&quot;
Response.Cookies(&quot;PC_or_CAD&quot;).Expires = Date() + 365
Response.Redirect &quot;COCO_PC.asp&quot;
Else
Response.Cookies(&quot;PC_or_CAD&quot;)=&quot;You use a CAD system.&quot;
Response.Cookies(&quot;PC_or_CAD&quot;).Expires = Date() + 365
Response.Redirect &quot;COCO_CAD.asp&quot;
end if
%>

I hope some one can help me with this!
 
Assuming this page is write_cookie.asp, and the form is recursive, then put all this code before any of your html and it should get it moving for you:

<%
dim PC_or_CAD
PC_or_CAD=Request.Form(&quot;PC_or_CAD&quot;)

if PC_or_CAD=&quot;PC&quot; then
Response.Cookies(&quot;PC_or_CAD&quot;)=&quot;You use a PC.&quot;
Response.Cookies(&quot;PC_or_CAD&quot;).Expires = Date() + 365
Response.Redirect &quot;COCO_PC.asp&quot;
ElseIf PC_or_CAD=&quot;CAD&quot; then
Response.Cookies(&quot;PC_or_CAD&quot;)=&quot;You use a CAD system.&quot;
Response.Cookies(&quot;PC_or_CAD&quot;).Expires = Date() + 365
Response.Redirect &quot;COCO_CAD.asp&quot;
end if
%>

didn't change much, only that the variable must have something in there before any code is executed, and if the code is executed, and the cookie is written, the page will just go ahead and wisk them off to the other page, instead of showing them the choices again.

If the value is empty, then we'll assume the page is a fresh load, and we'll display the choices.

hope that helps! :)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top