• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Form Validation

New Here ,
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

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.

TOPICS
Advanced techniques

Views

484

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 18, 2008 Sep 18, 2008
<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" ...

Votes

Translate

Translate
LEGEND ,
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

To do it on the form page, write some custom javascript to go along with whatever cfform gives you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

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"/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

LATEST
<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"/>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

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);">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation