Hide Form Field based on Another Form Selection

I have a form that has various fields.  In particular, if a user selects a specific value on one field, then I want another field to appear.

So if user selects 'Yes' to field 1, then I want field 2 to appear.  If user selects, 'No' to field 1, then I want to keep field 2 invisible to the user.
<!--- Dashboard Changes Required Options --->
<CFSET d = 2>
<CFSET selDBChReq = StructNew()>
<CFSET selDBChReq.value[1] = "1">
<CFSET selDBChReq.value[2] = "0">
<CFSET selDBChReq.description[1] = "Yes">
<CFSET selDBChReq.description[2] = "No">
<CFLOOP INDEX="dd" FROM="1" TO="#d#">
   <CFIF selDBChReq.value[dd] EQ varDBChReq>
      <CFSET selDBChReq.tag[dd] = " SELECTED">
   <CFELSE>
      <CFSET selDBChReq.tag[dd] = "">
   </CFIF>
</CFLOOP>

<FORM NAME="frmEditData" ACTION="edit_data.cfm" METHOD="post">
<table>
<TR>
	<TD CLASS="form_label" ALIGN="left" NOWRAP>Field 1</TD>
    <TD ALIGN="left">
       <SELECT NAME="edtDBChReq" CLASS="form_combo_normal" STYLE="width:124px;">
       <CFLOOP INDEX="dd" FROM="1" TO="#d#">
		<CFIF #selDBChReq.description[dd]# EQ #qryEDT.strDash#>
          <CFOUTPUT>
          <OPTION VALUE="#selDBChReq.value[dd]#"#selDBChReq.tag[dd]# selected>#selDBChReq.description[dd]#</OPTION></CFOUTPUT>
		<CFELSE>
          <CFOUTPUT>
          <OPTION VALUE="#selDBChReq.value[dd]#"#selDBChReq.tag[dd]#>#selDBChReq.description[dd]#</OPTION></CFOUTPUT>        
        </CFIF>
       </CFLOOP>
       <CFOUTPUT>
       </SELECT>
    </TD></CFOUTPUT>
</TR>
<!!----this part needs hidden unless 'yes' is selected above ----->
<TR>
 <TD CLASS="form_label" ALIGN="left">Field 2</TD>
 <TD ALIGN="left"><SELECT NAME="edtDBChTyp" CLASS="form_combo_normal" STYLE="width:124px;">
 <CFLOOP QUERY="qryDBChTyp">
    <CFIF #qryDBChTyp.br_dashchangetype_id# EQ #qryEDT.intBR_DashChangeType_ID#>
       <CFOUTPUT>
       <OPTION VALUE="#qryDBChTyp.br_dashchangetype_id#" SELECTED>#qryDBChTyp.br_dashchangetype_description#</OPTION></CFOUTPUT>
    <CFELSE>
       <CFOUTPUT>
       <OPTION VALUE="#qryDBChTyp.br_dashchangetype_id#">#qryDBChTyp.br_dashchangetype_description#</OPTION></CFOUTPUT>
    </CFIF>
 </CFLOOP>
 <CFOUTPUT>
 </SELECT>
 </TD></CFOUTPUT>
</TR>
</table>
</form>

Open in new window

Lee R Liddick JrReporting AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
Try a bit of jquery

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
   toggleRow($('#yourList').val());
   $('#yourList').change(function(){
      toggleRow($(this).val());
   });
 });
 function toggleRow(value) {
    if (value == "1") // 1 == yes
       $('#yourListRow').show();
    else
       $('#yourListRow').hide();
 }
</script>
</head>
<body>
<FORM NAME="frmEditData" ACTION="edit_data.cfm" METHOD="post">
<table>
<TR>
      <TD CLASS="form_label" ALIGN="left" NOWRAP>Field 1</TD>
    <TD ALIGN="left">
       <SELECT id="yourList" NAME="edtDBChReq" CLASS="form_combo_normal" STYLE="width:124px;">
                  <OPTION value="1">Yes</OPTION>
                  <OPTION value="0">No</OPTION>
       </SELECT>
    </TD>
</TR>
<!!----this part needs hidden unless 'yes' is selected above ----->
<TR id="yourListRow">
 <TD CLASS="form_label" ALIGN="left">Field 2</TD>
 <TD ALIGN="left">
      <SELECT NAME="edtDBChTyp" CLASS="form_combo_normal" STYLE="width:124px;">
            <OPTION value="1">some option 1</OPTION>
       </SELECT>
 </TD>
</TR>
</table>
</form>
</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZvonkoSystems architectCommented:
My proposal needs no jQuery.

Add an onChange event handler to your select:
<SELECT NAME="edtDBChReq" CLASS="form_combo_normal" STYLE="width:124px;" onChange="ShowHideSel(this)" >

Open in new window

Define this two functions anywhere on the page but best at the top of page:
<script>
function ShowHideSel(theSel){
  $("idSeconField").style.display=(theSel.value=="1")?"":"none";
}
function $(theID){
  return document.getElementById(theID);
}
</script>

Open in new window

And give your <tr> the used ID from upper function:
<TR id="idSeconField">

Open in new window

OK, now check it.
0
_agx_Commented:
Don't forget to also call the function when the page loads to set the row visibility,  like the jquery example does.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ZvonkoSystems architectCommented:
If you want that initial setting to addapt to page load time then for that is this my trick:

<SELECT NAME="edtDBChReq" CLASS="form_combo_normal" STYLE="width:124px;" onChange="ShowHideSel(this)" > 
<script>document.forms[0].edtDBChReq.onchange();</script>

Open in new window

0
ZvonkoSystems architectCommented:
Of course the fine art is to put the <script> AFTER the </select>

I posted it together to make it better visible.

0
ZvonkoSystems architectCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.