2 Replies - 438 Views - Last Post: 03 October 2012 - 08:47 AM

#1 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

Checkbox Not Replicating Values

Posted 02 October 2012 - 08:48 AM

I am trying to write a from where a checkbox replicates the values of the address fields. Simple enough, but it's not working, and I do not see any errors.

Here is a piece of the code, Any idea what I could be doing wrong here?


 $("#referralForm1").validate({
		rules: {
			Referral_Name_T: "required",
			Referral_Company_T: "required",
			Referral_Address_T: "required",
			Referral_City_T: "required",
			Referral_State_T: "required",
			
			Referral_Zip_T: {
				required: true,
				zipCode: true
			},
			
			Referral_PhoneFull_T: {
				required: true,
				phoneNumber: true
			},
		
			Referral_Email_T: {
				required: true,
				email: true,
				remote: { url: "/bin/ajax/checkEmail.a4p" }
			},
			Referral_EmailConfirm_T: {
				required: true,
				email: true,
				equalTo: "#Referral_Email_T"
			},
			
			Referral_PayToName_T: "required",
            Referral_PayToAddress_T: "required",
			Referral_PayToCity_T: "required",
			Referral_PayToState_T: "required",
			
			Referral_PayToZip_T: {
				required: true,
				zipCode: true
			},
				
		}
	});
	
	 $( document ).ready( function(){
      $( '#SameAsAbove_T' ).click( function() {
 
      // if the #sameaddress checkbox is checked copy information from these forms.
      if( $( '#SameAsAbove_T' ).is( ':checked' ) ){
        $( '#Referral_Address_T' ).val( $( '#Referral_PayToAddress_' ).val() );
        $( '#Referral_City_T' ).val( $( '#Referral_PayToCity_T' ).val() );
        $( '#Referral_State_T' ).val( $( '#Referral_PayToState_T' ).val() );
        $( '#Referral_Zip_T' ).val( $( '#Referral_PayToZip_T' ).val() );
      }
      else
      {
        // if the #sameaddress checkbox is not checked leave the pay to address text boxes as empty. 
        $( '#Referral_PayToAddress,#Referral_PayToCity_T,#Referral_PayToState_T,#Referral_PayToZip_T' ).val( '' );
      }
    });
  });




Is This A Good Question/Topic? 0
  • +

Replies To: Checkbox Not Replicating Values

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Checkbox Not Replicating Values

Posted 02 October 2012 - 02:06 PM

Have tried using a debugger like Firebug and setting a breakpoint in your click handler?
Was This Post Helpful? 0
  • +
  • -

#3 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

Re: Checkbox Not Replicating Values

Posted 03 October 2012 - 08:47 AM

I did finally get it working. It was an ID issue, it turns out the ID wasn't in the HTML. Anyway, I'm working on getting the form values to change if the checkbox is checked, any clue how to accomplish this? Basically if I put in 12345 Elm St. and then switch it to 12453 Elm St. I would like the form to pick up on that. I'd like to do it all in one if statement, but for some reason I can't get my head around this. Any help would be fantastic.

$("#Referral_Address_T,#Referral_City_T,#_Referral_State_T,#Referral_Zip_T").change(function(){
    if ($("Referral_SameAsAbove_T").is(':checked')) {
 if( this.id.indexOf('Referral_Address_T') > -1){
            $("#Referral_PayToAddress_T").val($(this).val());
         }




The part that's getting me is the last 2 lines which were taken from my initial attempt when I used 4 if statements, I'm sort of new to Jquery, and need it to go from whatever input line the user is currently on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1