Link to home
Start Free TrialLog in
Avatar of khan02
khan02Flag for United States of America

asked on

Coldfusion Flash form CF7

Hi i am creating a cf flash form where client has a Permanent Address and Current Address.
if clients both address are same, then i want client to fill out only permanent Address and select a check box which indicates " if address are same" , and by selecting the check box, Current address fields should be filled automatically with all the values entered in Permanent Address.

How can i do that. i will be glad to get any help with examples.

regards
khan
Avatar of _agx_
_agx_
Flag of United States of America image

Just use the checkbox's onClick method to update the text field value.  If you have multiple fields, you should create a function for this.
<cfform format="flash">
	<cfinput type="checkbox" name="SameAddresses" label="Addresses are the same" onClick="if(SameAddresses.selected){CurrentAdress.text = PermanentAdress.text;}">
	<cfinput type="text" name="PermanentAdress" label="Permanent Address">
	<cfinput type="text" name="CurrentAdress" label="Current Address">
</cfform>

Open in new window

Avatar of khan02

ASKER

here is my function,

<cfsavecontent variable="addr">
      Con_Address.text = Perm_Address.text;
      Con_City.text = Perm_City.text;
      Con_State.selected = Perm_State.selected;
</cfsavecontent>


Here is the code into form,

<!--- CURRENT MAILING ADDRESS --->
                        <cfformgroup type="panel" label="Current Mailing Address">
                              <cfinput type="text" label="Number and Street" name="Con_Address" value="#qGetData.Con_Address#" required="true" message="" maxlength="255">
                              <cfinput type="text" label="City" name="Con_City" value="#qGetData.Con_City#" required="true" message="" maxlength="255" width="200">
                              <cfselect name="Con_State" label="State" maxlength="255" required="true" message="You must enter a State for Current Mailing Address" width="100">
                                    <option></option>
                                       <cfloop query="qStates">
                                       <option value="#Abbreviation#" <cfif #qGetData.Con_State# is #Abbreviation#>selected</cfif>>#Name#</option>
                                    </cfloop>            
                              </cfselect>
                              
                              <cfselect name="Con_Country" width="200" label="Country" required="true" message="You must a Country for Current Mailing Address">
                                       <option></option>
                                    <cfloop query="qCountries">
                                       <option value="#CountryABB#" <cfif #qGetData.Con_Country# is #CountryAbb#>selected</cfif>>#CountryName#</option>
                                    </cfloop>
                                  </cfselect>
                        <!--- </cfformgroup> --->
                        <!--- END OF CURRENT MAILING ADDRESS --->
                        
                        <cfinput type="checkbox" name="SameAddress" label="Addresses are the same" onClick="#addr#">
                        
                        
                        <!--- PERMANENT MAILING ADDRESS --->
                        <!--- <cfformgroup type="panel" label="Permanent Address"> --->
                              <cfformitem type="hrule" style="" >
                                    <cfinput type="text" label="Number and Street" name="Perm_Address" value="#qGetData.Perm_Address#" required="true" message="" maxlength="255">
                                    <cfinput type="text" label="City" name="Perm_City" value="#qGetData.Perm_City#" required="true" message="" maxlength="255" width="200">
                                    <cfselect name="Perm_State" label="State" maxlength="255" required="true" message="You must enter a State for Permanent Mailing Address" width="100">
                                          <option></option>
                                             <cfloop query="qStates">
                                             <option value="#Abbreviation#" <cfif #qGetData.Perm_State# is #Abbreviation#>selected</cfif>>#Name#</option>
                                          </cfloop>            
                                    </cfselect>
                                    
                                    <cfselect name="Perm_Country" width="200" label="Country" required="true" message="You must a Country for Permanent Mailing Address">
                                             <option></option>
                                          <cfloop query="qCountries">
                                             <option value="#CountryABB#" <cfif #qGetData.Perm_Country# is #CountryAbb#>selected</cfif>>#CountryName#</option>
                                          </cfloop>
                                        </cfselect>
                              </cfformitem>
                        <!--- </cfformgroup> --->
                        </cfformgroup>


this is not working tho, need help please.
                        
Avatar of khan02

ASKER

here is the update from your code, i created a function but when i check the box, it only fills out the fisrt address field (CurrentAdress), and the other one is blank. see code below,

<cfsavecontent variable="SameAddresses">
      if(SameAddresses.selected)
      {
            CurrentAdress.text = PermanentAdress.text;
            Perm_City.text = Con_City.text;
            
      }
</cfsavecontent>

      

<cfform format="flash">
       <!---  <cfinput type="checkbox" name="SameAddresses" label="Addresses are the same" onClick="if(SameAddresses.selected){CurrentAdress.text = PermanentAdress.text;}"> --->
        <cfformgroup type="panel" label="Testing">
                  <cfinput type="text" name="PermanentAdress" label="Permanent Address">
                  <cfinput type="text" name="Perm_City" label="City">
         
            
            <cfinput type="checkbox" name="SameAddresses" label="Addresses are the same" onClick="#SameAddresses#">
             
            
                  <cfinput type="text" name="CurrentAdress" label="Current Address">
                  <cfinput type="text" name="Con_City" label="City">
             </cfformgroup>
</cfform>
You have the fields reversed.  I think it should be:

<cfsavecontent variable="SameAddresses">
      if(SameAddresses.selected)
      {
            CurrentAdress.text = PermanentAdress.text;
            Perm_City.text = Con_City.text;
            Con_City.text = Perm_City.text;
      }
</cfsavecontent>
BTW - If you are using MX 7.0.2 + , you can create functions using cfformitem type="script", instead of using cfcontent.
Avatar of khan02

ASKER

i am using coldfusion Mx 7, still it only duplicates the first field, as i mentioned earlier
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America 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
Avatar of khan02

ASKER

i am using coldfusion Mx 7, still it only duplicates the first field, as i mentioned earlier
Avatar of khan02

ASKER

see below,

ColdFusion Server Developer        7,0,2,142559
Template       /CFD/test10.cfm
Time Stamp       05-Mar-09 03:07 PM
Avatar of khan02

ASKER

it does change the CurrentAddress field with PermanentAddress, but it it does not change field Con_City with Perm_City?
It works perfectly fine for me.  Did you clear you cache as I mentioned?  If you are still using a cached copy you would not see the changes.  

When I type in a sample address in the first set of textboxes:
 
first address: Perm Address Test
first city:  Perm City Test

It populates the second set of text boxes with the same information when the box is checked:

second address: Perm Address
second city:  Perm City Test

> it only fills out the fisrt address field (CurrentAdress), and the other one is blank

Stupid questions, but are you _sure_ you:

a) are running the updated code
b) cleared cache
c) typed something in both fields

I ask because I don't really see another reason why the code would not be working for you.  It works perfectly fine for me.

> ColdFusion Server Developer        7,0,2,142559

Yes, then you can use scripts:

Avatar of khan02

ASKER

ok, now it's working for both fields. how can i do the same for STATE and COUNTRY, since state and country fields are <cfselect> type, not a text type?

If both lists have the same contents, in the _same order_, just use the selectedIndex property instead of "text":

SomeList.selectedIndex = OtherList.selectedIndex;
Avatar of khan02

ASKER

thnks that resolves my problem.