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 August 4th, 2004, 10:52 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Radio Button Problems!

Hi there

Is anyone able to help me with the following problem.

I have a page called vote.asp which contains 3 radio buttons, all with the same name so that only one can be picked, but with different values associated with each one.

<input name="vote" type="radio" value="Sally" />
<input name="vote" type="radio" value="Polly" />
<input name="vote" type="radio" value="Other" />

I also have a textfield on this page, called "Other" so that if the user 'checks' the radio button with value="Other", they have to enter in a name into the textfield.

When the user clicks on the submit button, this goes to a process page, called process_vote.asp which adds the chosen value into a database and then redirects them to a thank you page.

However, if the user chooses the 'other' radio button option, they MUST fill in the textfield. I've tried using:

if (Request("vote") = "Other" and Request("Other") = "" then....

but it's not working.

Radio buttons always confuse me!! Anyone know the correct code? Also, if the user is taken back to the vote.asp page, how can I keep this radio button 'checked' so that don't have to press it again?

Thanks in advance

Lucy


 
Old August 4th, 2004, 11:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Lucy,

In your case it is always better to submit to the same page (vote.asp), so that it would be easy to set the radio button on in case of errors. Also on getting all those values through, you can add that to the database and redirect to another page, so that, on refresh of the same page, the database addition code would not get executed again and again and that way you can avoid duplicates.

So request for radio button's value, if OTHER, check if Other textbox is empty and reset the value on the same page.

Code:
<%
txtother = Request("Other")
vote = Request("vote")
If vote = "Other" and len(txtOther) = 0 then 
    Response.write "You can't escape, enter a value in OTHER TextBox."
End If
%>
...
...
...
<input name="vote" type="radio" value="Sally" <%if vote="Sally" then %> CHECKED <%End If%>>
<input name="vote" type="radio" value="Polly" <%if vote="Polly" then %> CHECKED <%End If%>>
<input name="vote" type="radio" value="Other" <%if vote="Other" then %> CHECKED <%End If%>>

<input type = "text" name="other" value='<%=txtOther%>'>
This would reselect the radio button which was already selected. But I am not sure if that attribute of Radio button is CHECKED or SELECTED. You can use SELECTED if you don't get the value back, as I don't have enough time to check that out in my PC.

Also when you check for values in form variable, always check for its length, so that if anything else comes with it other than valid values you can always trace that out.
This should help you out.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
radio button anwarraja Javascript 3 September 18th, 2007 08:18 PM
radio-button grstad HTML Code Clinic 3 February 28th, 2006 08:32 AM
Radio Button hoailing22 ASP.NET 1.0 and 1.1 Basics 1 June 2nd, 2005 12:08 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM
radio button damnnono_86 Access 5 October 28th, 2003 02:17 AM





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