Solved

Coldfusion: How to I validate radio button group on form submission

Posted on 2010-11-17
1
1,407 Views
Last Modified: 2012-05-10
I have a Coldfusion form using CFForm.  I'm using CF's validation functionality for most of the elements but I'm not able to get it working for the radio buttons.  I have two groups of radio buttons on the same page that I want to have none of the buttons selected when the user first gets to the page but each group is required to have one button selected before proceeding to the next page.  I believe this can be done with JavaScript but how to integrate it with a form already using CFForm's built in validation?

thanks in advance
0
Comment
Question by:robinsf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 34162178
Here you see two methods how to check Radio buttons in your CFFORM:
<script>
function myRadioCheck(){
  theForm = document.forms.myForm;
  for(var i=0;i<theForm.myseminar.length;i++){
    if(theForm.myseminar[i].checked) return true;
  }
  alert("Select mySeminar value.");
  return false;
}


</script>
<cfform name="myForm" method="post" onSubmit="return myRadioCheck()" >

<cfinput type="radio" name="seminar" value="1" required="yes" message="Select Seminar value." > 1 
<cfinput type="radio" name="seminar" value="2" required="yes" message="Select Seminar value." > 2 
<cfinput type="radio" name="seminar" value="3" required="yes" message="Select Seminar value." > 3 
<br>

<input type="radio" name="myseminar" value="a" > A 
<input type="radio" name="myseminar" value="b" > B 
<input type="radio" name="myseminar" value="c" > C 
<br>
<cfinput name="startDate" type="datefield" label="date:" mask="mm/dd/yyyy" required="yes" />
<br>
<input type="submit" value="mySubmit" >

</cfform>


If it is not confusing to you this version gets the variable theForm passed from ColdFusion:


<script>
function myRadioCheck(theForm){
  for(var i=0;i<theForm.myseminar.length;i++){
    if(theForm.myseminar[i].checked) return true;
  }
  alert("Select mySeminar value.");
  return false;
}


</script>
<cfform name="myForm" method="post" onSubmit="return myRadioCheck(_CF_this)" >

<cfinput type="radio" name="seminar" value="1" required="yes" message="Select Seminar value." > 1 
<cfinput type="radio" name="seminar" value="2" required="yes" message="Select Seminar value." > 2 
<cfinput type="radio" name="seminar" value="3" required="yes" message="Select Seminar value." > 3 
<br>

<input type="radio" name="myseminar" value="a" > A 
<input type="radio" name="myseminar" value="b" > B 
<input type="radio" name="myseminar" value="c" > C 
<br>
<cfinput name="startDate" type="datefield" label="date:" mask="mm/dd/yyyy" required="yes" />
<br>
<input type="submit" value="mySubmit" >

</cfform>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question