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!

Radio Option Buttons

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
0
0
CA
I have an radio option button. How do I determine if its been checked or not?

<CFIF #SelectAddress# EQ 1>

I tried this but it didn't work. #SelectAddress# is the name of the radio option and can have any number of values.

Thanks.
 
To check if the radio button is checked or not, use the followin':
<cfif isDefined(&quot;SelectAddress&quot;)>
In case the radio button is not checked, this statement will return 0 (false), otherwise it will return 1 (true).

To check the value of the radio button, use the followin': <cfif #SelectAddress# is &quot;1&quot;>
<cfif #SelectAddress# is &quot;2&quot;> .. etc ..

I hope this will help you.
<CFBikzit Text=&quot;Hi There&quot;>
 
hi khurram

Your CFIF syntax is fine, but you should always receive some value for #selectAddress#. If not, make sure you default one of the options on your form page to checked--whatever the value.

<input type=&quot;radio&quot; name=&quot;x&quot; value=0 CHECKED>None
<input type=&quot;radio&quot; name=&quot;x&quot; value=1>1
<input type=&quot;radio&quot; name=&quot;x&quot; value=2>2

Your action page should then always be able to find selectAddress.






 
dear strantheman,
sometimes you have to leave the radio buttons unchecked. for example if you have two radio-buttons, one has the value 'Male' and the other has the value 'Female', then it's not a good idea to make one of these buttons checked by default, cos the user might forget to select his/her gender, and then the form will accept the value of the radio-button cos it's checked by default .. when you leave these buttons unchecked, you have the chance to remind the user to select his/her gender. i hope you got it :) <CFBikzit Text=&quot;Hi There&quot;>
 
hey Bikzit

Yes correct. But khurram's question is about the action page, and he's trying to reference a variable that isnt there. Im just saying the variable should always be passed, whether you wait for the user to check it, or force one checked by default.

If he has asked how to validate his form it would be a different issue. But yea I know what you mean, there's some questions that must be answered.
 
dear strantheman,
you're completely right. but i just tried to make that idea clear to khurram. ok man? :) <CFBikzit Text=&quot;Hi There&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top