Skip to main content
Participant
September 18, 2008
Answered

Form Validation

  • September 18, 2008
  • 2 replies
  • 540 views
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 has been closed for replies.
Correct answer Newsgroup_User
<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"/>
>

2 replies

Inspiring
September 18, 2008
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);">
Inspiring
September 18, 2008
To do it on the form page, write some custom javascript to go along with whatever cfform gives you.
rudocastAuthor
Participant
September 18, 2008
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"/>