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

How to validate a radio button?

Status
Not open for further replies.

tina2

IS-IT--Management
Joined
May 1, 2001
Messages
169
Location
US
Can anyone tell me how to validate a radio button in Cold Fusion? I have a form with three yes or no questions. One is optional, so I want to make two of them required, but leave the option to leave one of them blank.

Any suggestions?

Thanks,
Kristine
 
if form radio button is checked, it will return value "on", e.g.:

<cfif IsDefined(&quot;Form.radioB&quot;)>
<cfoutput>#Form.radioB#</cfoutput>
</cfif>


<form action=&quot;test.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;testing&quot; id=&quot;testing&quot;>
<input type=&quot;radio&quot; name=&quot;radioB&quot;>
<input type=&quot;submit&quot; name=&quot;dd&quot;>

</form>



Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Not sure I understand what you want, content-wise. You want three yes/no questions with only two of them required? Are you deciding which two are required up front or does the user decide that? That makes a little bit of difference when you're processing the form.

But like WWebSpider said, if they don't answer yes or no then the FORM variable will not be defined. If they do select one of them then it's just like any other variable.

Hint: if you want to force them to choose yes or no on something, make one of them checked by default

<input type=radio name=&quot;question&quot; value=&quot;yes&quot; checked> yes<br>
<input type=radio name=&quot;question&quot; value=&quot;no&quot;> no

Because once a set of radio buttons has a selection you can't un-select it (try it!).
 
BTW, if you use thi on a cluster, you can do this number:

<cfform action=&quot;test.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;testing&quot; id=&quot;testing&quot;>

<cfinput type=&quot;Radio&quot; value=&quot;someValue&quot; name=&quot;someName&quot; required=&quot;yes&quot;>

<input type=&quot;submit&quot; name=&quot;dd&quot;>

</cfform>

by using cfform tag and required attribute, on submit event, if radio button is required but not checked, user will receive alert error message box Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Thanks for your help!
This is so much easier than JavaScript!

Kristine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top