Solved

What is the best way to hide divs in cf8 while the client is filling out a form and make visible based on seection.

Posted on 2009-04-07
7
228 Views
Last Modified: 2013-12-24
I have a form that people select either "vacation" or "residential" there are certain fields that need to be hidden if either is selected. They need to be on the page just hidden if they are not relevent.


I use CF8.
propert type: Vacation Residential (select Property type)
NightlyRates (this is for property type = Vacation and should be hidden if residential is selected)
Condo fees (this is for property type = Vacation and should be hidden if residential is selected)
School district (this is for property type = Residential and should be hidden if vaction is selected)


<cfform target="_self" method="post" name="ajaxform" preloader="no">
  <p>
    propert type:
<cfselect enabled="No" name="Property type"  id="propertytype" multiple="no"> 
      <option value="Vacation">Vacation</option>
    <option value="Residential">Residential</option>
    </cfselect>
  (select Property type)</p>
  
<p>NightlyRates
    <label for="textfield"></label>
    <input name="Nightlyrates" type="text" id="nightlyrates" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)<br />
  </p>
 
  <p>Condo fees 
    <input name="condofees" type="text" id="textfield2" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)</p>
  <p>School district 
    <input name="schooldistrict" type="text" id="schooldistrict" size="12" />
  (this is for property type = Residential and should be hidden if vaction is selected)</p>
  <p>
    <label for="button"></label>
    <input type="submit" name="button" id="button" value="Submit" />
  </p>
</cfform>

Open in new window

0
Comment
Question by:LeadCo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24084864
with a little bit of jQuery majic this is as easy as pie. see attached code
(re-worked a bit to add default selection to the cfselect and to set default display for the other fields. classes were added to the <p> tags containing your form fields so js function can easily find and show/hide them).


download jQuery js library from http://jquery.com

Azadi
<script type="text/javascript" src="/path/to//jquery.js"></script>
<script type="text/javascript">
showhidefields = function(el){
	$('._'+el).hide();
	$('.'+el).show();
}
</script>
<cfparam name="form.propertytype" default="Vacation">
<cfform target="_self" method="post" name="ajaxform" preloader="no">
  <p>
    propert type:
<cfselect enabled="No" name="propertytype"  id="propertytype" multiple="no" onChange="showhidefields(this.value);"> 
<option value="Vacation" <cfif form.propertytype eq "Vacation">selected="selected"</cfif>>Vacation</option>
<option value="Residential">Residential</option>
</cfselect>
  (select Property type)</p>
  
<p class="Vacation _Residential" <cfif form.propertytype eq "Residential">style="display:none"</cfif>>NightlyRates
    <label for="textfield"></label>
    <input name="Nightlyrates" type="text" id="nightlyrates" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)<br />
  </p>
 
  <p class="Vacation _Residential"<cfif form.propertytype eq "Residential">style="display:none"</cfif>>Condo fees 
    <input name="condofees" type="text" id="textfield2" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)</p>
  <p class="_Vacation Residential"<cfif form.propertytype eq "Vacation">style="display:none"</cfif>>School district 
    <input name="schooldistrict" type="text" id="schooldistrict" size="12" />
  (this is for property type = Residential and should be hidden if vaction is selected)</p>
  <p>
    <label for="button"></label>
    <input type="submit" name="button" id="button" value="Submit" />
  </p>
</cfform>

Open in new window

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24084879
sorry, forgot to add <cfif> into the second <option>:

<option value="Residential" <cfif form.propertytype eq "Residential">selected="selected"</cfif>>Residential</option>

Azadi
0
 

Author Comment

by:LeadCo
ID: 24089291
To host jquery does it require linux, I have dedicated server windows 2003.  I went to jquery.com and found that it does not appear to be available on a windows server (jquery).
Is that correct? What do you suggest?
0
Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

 

Author Comment

by:LeadCo
ID: 24090054
Ok I am a bonehead. Ignore that last post. I just got educated. Its live and working.  One last question on this subject.

If I want to start the form with only the property type selection field visible and keep same function as above. What changes would need to be made to script?  Here is code I have:
<script type="text/javascript" src="/jscript/jquery.js"></script>
<script type="text/javascript">
showhidefields = function(el){
	$('._'+el).hide();
	$('.'+el).show();
}
</script>
<cfparam name="form.propertytype" default="Vacation">
<cfform target="_self" method="post" name="ajaxform" preloader="no">
  <p>
    propert type:
<cfselect enabled="No" name="propertytype"  id="propertytype" multiple="no" onChange="showhidefields(this.value);"> 
<option value="Vacation" <cfif form.propertytype eq "Vacation">selected="selected"</cfif>>Vacation</option>
<option value="Residential" <cfif form.propertytype eq "Residential">selected="selected"</cfif>>Residential</option>
</cfselect>
  (select Property type)</p>
  
<p class="Vacation _Residential" <cfif form.propertytype eq "Residential">style="display:none"</cfif>>NightlyRates
    <label for="textfield"></label>
    <input name="Nightlyrates" type="text" id="nightlyrates" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)<br />
  </p>
 
  <p class="Vacation _Residential"<cfif form.propertytype eq "Residential">style="display:none"</cfif>>Condo fees 
    <input name="condofees" type="text" id="textfield2" size="5" />
  (this is for property type = Vacation and should be hidden if residential is selected)</p>
  <p class="_Vacation Residential"<cfif form.propertytype eq "Vacation">style="display:none"</cfif>>School district 
    <input name="schooldistrict" type="text" id="schooldistrict" size="12" />
  (this is for property type = Residential and should be hidden if vaction is selected)</p>
  <p>
    <label for="button"></label>
    <input type="submit" name="button" id="button" value="Submit" />
  </p>
</cfform>

Open in new window

0
 

Author Comment

by:LeadCo
ID: 24090165
What I meant above was to start with only the cfselectbox visable and the rest invisable.
0
 

Author Comment

by:LeadCo
ID: 24090288
Ok I think I got it.

This code:
<script type="text/javascript" src="/jscript/jquery.js"></script>  (this calls the script)
<script type="text/javascript">
showhidefields = function(el){      (this sets is so that the selected either _vacation hides or _residential)
      $('._'+el).hide();
      $('.'+el).show();
}
</script>

The selection determines the value of  (el) either Vacation or residential.

<cfselect enabled="No" name="propertytype"  id="propertytype" multiple="no" onChange="showhidefields(this.value);">
<option value="Vacation" <cfif form.propertytype eq "Vacation">selected="selected"</cfif>>Vacation</option>
<option value="Residential" <cfif form.propertytype eq "Residential">selected="selected"</cfif>>Residential</option>
</cfselect>


I got it.

Thanks.
0
 

Author Closing Comment

by:LeadCo
ID: 31567384
Thanks Again!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question