Skip to main content
Participant
Sep 18, 2008 1:36 AM UTC
Answered

Form Validation

I am not sure if I am in the correct place to post this but I need help. First of all, I am new to ColdFusion and I am creating a Form. I have most of it validated. However, I am facing a little problem. I have a radio button with two choices, Yes and No, When Yes is Check I want a cftextarea field required. How could I do that? I would appreciate your help.

This topic is closed to new replies. Start a new post to keep the conversation going.
Newsgroup_UserCorrect answer
Inspiring
Sep 18, 2008 3:16 PM UTC
<script type="text/javascript">
<!--
function enableIt() {
document.myform.sHistExplain.disabled=0;
}
function checkIt(){
if (document.myform.sHistorial[0].checked == true) {
if (document.myform.sHistExplain.value.length < 1) {
alert('Please enter the Explanation');
document.myform.sHistExplain.focus();
return false;
}
}
}
//-->
</script>

<cfform name="myform" id="myform" method="post" action="actionpage.cfm"
onsubmit="return checkIt();">
<p>Yes
<cfinput type="radio" name="sHistorial" value="Yes" checked="no"
required="yes" message="Have you ever been placed on academic or
disciplinary probation, suspended or dismissed from any school or college?"
onClick="enableIt();" />
No
<cfinput name="sHistorial" type="radio" value="No" checked="no"
required="yes" message="Have you ever been placed on academic or
disciplinary probation, suspended or dismissed from any school or college?"
/>
</p>
<p>  </p>
<p>
<textarea name="sHistExplain" cols="100" rows="4" disabled="disabled"
id="sHistExplain"></textarea>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</cfform>


--
Ken Ford
Adobe Community Expert Dreamweaver/ColdFusion
Adobe Certified Expert - Dreamweaver CS3
Fordwebs, LLC
http://www.fordwebs.com


"rudocast" <webforumsuser@macromedia.com> wrote in message
news:gato56$62a$1@forums.macromedia.com...
> Do yo think the onClick event can help me with this? How could I pass the
> YES
> value to the required attribute?
>
> ---------------------
>
> Yes <cfinput type="radio" name="sHistorial" value="Yes" checked="no"
> required="yes" message="Have you ever been placed on academic or
> disciplinary
> probation, suspended or dismissed from any school or college?" />
> No <cfinput name="sHistorial" type="radio" value="No" checked="no"
> required="yes" message="Have you ever been placed on academic or
> disciplinary
> probation, suspended or dismissed from any school or college?" />
>
> ---------
>
> textarea
>
> <cftextarea name="sHistExplain" rows="4" cols="100" id="sHistExplain"
> required=" Yes if the radio button is Yes" message="Explain please"
> enabled="yes"/>
>

4 replies

Inspiring
Sep 18, 2008 2:33 PM UTC
I like using the form's onsubmit event for validation. When using cfform, there is one extra step you need because cfform uses it's own javascript.

js part
function yourFunction(theform) {

validation code goes here
}

form part
<cfform onsubmit="return yourFunction(this);">
Translate
Inspiring
Sep 18, 2008 2:13 AM UTC
To do it on the form page, write some custom javascript to go along with whatever cfform gives you.
Translate
rudocastAuthor
Participant
Sep 18, 2008 2:21 PM UTC
Do yo think the onClick event can help me with this? How could I pass the YES value to the required attribute?

---------------------

Yes <cfinput type="radio" name="sHistorial" value="Yes" checked="no" required="yes" message="Have you ever been placed on academic or disciplinary probation, suspended or dismissed from any school or college?" />
No <cfinput name="sHistorial" type="radio" value="No" checked="no" required="yes" message="Have you ever been placed on academic or disciplinary probation, suspended or dismissed from any school or college?" />

---------

textarea

<cftextarea name="sHistExplain" rows="4" cols="100" id="sHistExplain" required=" Yes if the radio button is Yes" message="Explain please" enabled="yes"/>
Translate