Link to home
Start Free TrialLog in
Avatar of LeadCo
LeadCo

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry, forgot to add <cfif> into the second <option>:

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

Azadi
Avatar of LeadCo
LeadCo

ASKER

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?
Avatar of LeadCo

ASKER

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

Avatar of LeadCo

ASKER

What I meant above was to start with only the cfselectbox visable and the rest invisable.
Avatar of LeadCo

ASKER

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.
Avatar of LeadCo

ASKER

Thanks Again!