3

We have a landing page in ExactTarget that includes form fields for two sets of contact information (mailing address vs. billing address). We have added a check box that allows the user to reuse the mailing address information they entered for the billing address information so they don't have to enter the information twice. We are using javascript for this. This works outside of ExactTarget, but not within ExactTarget. Is there a way to make this work? Here is the problematic code snippet:

<script>
    // make billing same as address
    $('input[name=same]').click(function() {
        //alert('Using the same address');  
        if ($("input[name=same]:checked").is(':checked')) { 
            $('#account_bill_fname').val($('#account_fname').val());
            $('#account_bill_company').val($('#account_company').val());
            $('#account_bill_address1').val($('#account_address1').val());
            $('#account_bill_address2').val($('#account_address2').val());
            $('#account_bill_city').val($('#account_city').val());             
            var state = $('select[name=account_state] option:selected').val(); 
            $('select[name=account_bill_state] option[value=' + state + ']').attr('selected','selected');     
            $('#account_bill_postal').val($('#account_postal').val());
            $('#account_bill_bizphone').val($('#account_bizphone').val());
            $('#account_bill_email').val($('#account_email').val());
        };              
    });

</script>
9
  • 1
    It appears like this is jQuery, but I'm not seeing where you are calling the jquery.js file. Also - welcome to the community! Jan 17, 2014 at 19:18
  • What error are you seeing in the JavaScript console?
    – Mike Chale
    Jan 17, 2014 at 19:30
  • I'm not seeing an error. It works fine outside of ExactTarget. It just doesn't work inside ExactTarget. Jan 17, 2014 at 19:32
  • Sorry, I'm still not quite sure what errors you are getting from this regarding jQuery. What is the <script src=".../jquery.js"> look like as well? Jan 17, 2014 at 19:35
  • 1
    <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.4.2/…> Jan 17, 2014 at 19:36

2 Answers 2

2

Your page has a couple errors -

Uncaught SyntaxError: Unexpected token { ~ pages.protective-email.com/:334 //This is working now
Uncaught ReferenceError: MM_preloadImages is not defined ~ pages.protective-email.com/:13 // this is in chrome dev tools - looks like a Dreamweaver function that isn't avaialable

Couple things I noticed, that you might want to clean up:

  • The script in question is loading outside the <body> tag, which typically could cause issues.
  • The script is currently loading with out being inside $(document).ready(function(){});.
  • The correct syntax for the selector should be $("INPUT[NAME='SAME']").

See if after correcting those items the issue still persists. I can't honestly explain why it would work locally, but something must be more forgiving on your local environment - it really shouldn't.

Your script should look like this -

 $(document).ready(function(){
    // make billing same as address
    $("INPUT[NAME='SAME']").click(function() {
    //alert('Using the same address');  
    if ($("input[name='same']:checked").is(':checked')) { 
      $('#MA_FullName').val($('#FullName').val());
      $('#MA_Company').val($('#Company').val());
      $('#MA_Address1').val($('#Address1').val());
      $('#MA_Address2').val($('#Address2').val());
      $('#MA_City').val($('#City').val());    
      $('#MA_ZIP').val($('#ZIP').val());
      $('#MA_Phone').val($('#Phone').val());
      $('#MA_Email').val($('#Email').val());         
      var state = $("select[name='State'] option:selected").val(); 
      $("select[name='MA_State'] option[value=" + State + "]").attr('selected','selected');     

      };              
    });
});

UPDATE

The code that is on the live site is showing as this:

 $(document).ready(function(){
    // make billing same as address
    $("INPUT[NAME='SAME']").click(function() {
    //alert('Using the same address');  
    if ($("input[name='same']:checked").is(':checked')) { 
      $('#MA_FullName').val($('#FullName').val());
      $('#MA_Company').val($('#Company').val());
      $('#MA_Address1').val($('#Address1').val());
      $('#MA_Address2').val($('#Address2').val());
      $('#MA_City').val($('#City').val());    
      $('#MA_ZIP').val($('#ZIP').val());
      $('#MA_Phone').val($('#Phone').val());
      $('#MA_Email').val($('#Email').val());         
      var state = $("select[name='State'] option:selected").val(); 
      $("select[name='MA_State'] option[value=" + State + "]").attr('selected','selected');     

      };              
    });
});

The reason why it is not working is due to the very first line - $("INPUT[NAME='SAME']") will never match your HTML element, because nothing on the page mathes, as jQuery is case-sensitive.

Not sure why that particular line is all caps, but that needs to be changed to same all lower case. That should solve your problem.

Here is a working jsFiddle to prove the point.

10
  • That is actually what I am using. For some reason, it cut part of the URL off when I pasted it here. Sorry about that. Jan 17, 2014 at 19:47
  • Can you share the landing page url? Jan 17, 2014 at 19:49
  • make sure to use HTTPS instead of HTTP. I've ran into that error before because Salesforce requires HTTPS Jan 17, 2014 at 19:59
  • @amatorVitae This isn't on Salesforce - it's on their product ExactTarget. It's worth a shot, but I haven't run into this before. Jan 17, 2014 at 20:01
  • 2
    It works! You are wonderful! Thanks so much for all of your help! Jan 20, 2014 at 19:03
0

It looks like you are using jQuery, and I'm assuming this is used on a VF page. At first glance, I think that the issue might be with using the reserved variable $ since Salesforce reserves that variable name for many of their own features.

Whenever I use jQuery, I override the $-shortuct by declaring another variable as the shortcut with jQuery.noConflict().

Example:

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"/>
<script>
    var j$=jQuery.noConflict();
    // now use "j$" wherever you would use "$"

    j$(document).ready(function(){

        alert('hi');

    });

</script>
2
  • 2
    This doesn't apply, the question is about ExactTarget's landing page solution. Jan 17, 2014 at 19:15
  • @amatorVitae - Kelly, thanks for your quick response and follow-up. I updated the post with a jquery tag. Hopefully someone will respond specific to ExactTarget landing pages. Thanks again. Jan 17, 2014 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .