1)If you are going to try
required="yes" validateat="onserver" message="Question 1 was not
answered and is required" in your check box, you need to change it
from <input type="checkBox"> to <cfinput type="checkBox"> That will
allow you to run the validation that you are trying to put in the
form.
2)<cfparam name="Question1" default=""> change that to <cfparam
name="Form.Question1" default="">
3) Use radio buttons instead
4)<cfif NOT IsDefined('#Question1#')>
Failure
<cfelse>
Success
</cfif>
Change that to
<cfif NOT IsDefined('#Form.Question1#')>
Failure
<cfelse>
Success
</cfif>
On 9/20/06, Randi Knutson <[EMAIL PROTECTED]> wrote:
> First I'd use radio buttons if they have to answer one answer for each
> question. That being said, here's my code to do that, fair warning
> though, JS is not my specialty so probably this isn't the most elegant
> solution!
>
> My form just had a series of questions with radio buttons, no other
> elements. If you have other elements, you'll need to modify this
> javascript accordingly.
>
> <!--start javascript include for head -->
> // validate radio buttons
>
> function validateForm() {
> // build array
> var h = "";
> var n = "";
> var c = 0;
> var a = new Array();
> for (i=0; i < document.myForm.elements.length; i++) {
> if (document.myForm.elements[i].type == "radio") {
> n = document.myForm.elements[i].name + "z"; // add letter to
> avoid
> search conflicts
> if (h.indexOf(n) == -1) {
> a[c] = n;
> h = h + n;
> c++;
> }
> }
> }
> // compile number of checked radios
> var d = 0;
> for (i=0; i < document.myForm.elements.length; i++) {
> if ( (document.myForm.elements[i].type == "radio") &&
> (document.myForm.elements[i].checked) ) {
> d++;
> }
> }
> // compare number of checked radios to length of array
> if (d != a.length) {
> alert ("Please attempt to answer all questions.");
> return false;
> }
> return true;
> }
> <-- end js include>
>
> <form method="post" action="yourAction.cfm" name="myForm" onsubmit="return
> validateForm(this);">
>
> </form>
>
> [email protected] on Wednesday, September 20, 2006 at 4:54 PM
> -0800 wrote:
> >Ok, first of all I want to thank all those who have helped me today and
> >you know who you are.
> >
> >I have several groups of checkboxes that are grouped together. The idea
> >is to select one answer for each question. Here is a following example:
> >
> ><tr>
> > <td colspan="2"><div align="left">1) To what extent did this program
> >meet your needs?</div></td>
> ></tr>
> ><tr>
> > <td colspan="2"><div align="left">
> >
> > <cfparam name="Question1" default="">
> > <input type="checkbox" name="Question1" value="Great Degree"
> >required="yes" validateat="onserver" message="Question 1 was not answered
> >and is required">A. Great Degree</input><br />
> >
> > <input type="checkbox" name="Question1" value="Moderate
> >Degree">B. Moderate Degree</input><br />
> >
> > <input type="checkbox" name="Question1" value="Small
> >Degree">C. Small Degree</input><br />
> >
> > <input type="checkbox" name="Question1" value="Not At
> >All">D. Not At All</input></div>
> > </td>
> ></tr>
> >
> >I tried using the code: <cfparam name="Question1" default="">
> >in there to add a default value but I don't think it worked. The
> >questions are in a form that is being sent to another page. How do I
> >make sure that an answer has been selected before proceeding?
> >
> >I have tried validating it on the next page with this:
> >
> ><cfif NOT IsDefined('#Question1#')>
> > Failure
> ><cfelse>
> > Success
> ></cfif>
> >
> >but this didn't work either.
> >
> >Can anyone point me in the right direction?
> >
> >Thanks,
> >-Gary
> >
> >
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2082
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15