Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Copying from billing address to mailing address if they are the same not working correctly

Copying from billing address to mailing address if they are the same not working correctly

Scheduled Pinned Locked Moved JavaScript
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    I have a form that asks users to provide their billing and shipping addresses. If the billing address is same as the mailing address, click a checkbox to copy the billing address information to mailing address boxes. So far, address, city and zip are getting copied from billing to mailing addresses but the State address is not getting copy. The billing State has a hardcoded value of WI for Wisconsin. That NEVER changes, hence it is hardcoded. The mailing address for State has a DropDownList of states, I am pretty sure that has to do with why the billing address for State is not getting cover over to mailing address for State. Can you guys please see what I am doing wrong? Here is what I am working with.

            $('#SameAsMailing').click(function () {
                 if ($('input\[name="SameAsMailing"\]').is(':checked')) { 
                 $('#mailStreetAddress').val($('#instAddress').val());
                 $('#mailCity').val($('#instAddressCity').val()); 
                 var thestate = $('#instAddressState option:selected').val();
                 if (thestate != "") {
                             $('#mailState option\[value="' + thestate + '"\]').prop('selected', true);
                      } 
                 $('#mailZip').val($('#instAddressZip').val());
                 }
               else
                {
                //Clear on uncheck
                $('#mailStreetAddress').val("");
                $('#mailCity').val("");
                $('#mailState option:eq(0)').prop('selected', true);
                $('#mailZip').val("");
               }
             }); 
           
    
        
          Install Address:
    		    
    	City:
                   
        City:
    	
    	State:
    	
    	Zip:
    
    Richard DeemingR 1 Reply Last reply
    0
    • S samflex

      I have a form that asks users to provide their billing and shipping addresses. If the billing address is same as the mailing address, click a checkbox to copy the billing address information to mailing address boxes. So far, address, city and zip are getting copied from billing to mailing addresses but the State address is not getting copy. The billing State has a hardcoded value of WI for Wisconsin. That NEVER changes, hence it is hardcoded. The mailing address for State has a DropDownList of states, I am pretty sure that has to do with why the billing address for State is not getting cover over to mailing address for State. Can you guys please see what I am doing wrong? Here is what I am working with.

              $('#SameAsMailing').click(function () {
                   if ($('input\[name="SameAsMailing"\]').is(':checked')) { 
                   $('#mailStreetAddress').val($('#instAddress').val());
                   $('#mailCity').val($('#instAddressCity').val()); 
                   var thestate = $('#instAddressState option:selected').val();
                   if (thestate != "") {
                               $('#mailState option\[value="' + thestate + '"\]').prop('selected', true);
                        } 
                   $('#mailZip').val($('#instAddressZip').val());
                   }
                 else
                  {
                  //Clear on uncheck
                  $('#mailStreetAddress').val("");
                  $('#mailCity').val("");
                  $('#mailState option:eq(0)').prop('selected', true);
                  $('#mailZip').val("");
                 }
               }); 
             
      
          
            Install Address:
      		    
      	City:
                     
          City:
      	
      	State:
      	
      	Zip:
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      samflex wrote:

      var thestate = $('#instAddressState option:selected').val();
      if (thestate != "") {
      $('#mailState option[value="' + thestate + '"]').prop('selected', true);
      }

      Try:

      var thestate = $('#instAddressState').val();
      if (thestate !== "") {
      $('#mailState').val(thestate);
      }


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        samflex wrote:

        var thestate = $('#instAddressState option:selected').val();
        if (thestate != "") {
        $('#mailState option[value="' + thestate + '"]').prop('selected', true);
        }

        Try:

        var thestate = $('#instAddressState').val();
        if (thestate !== "") {
        $('#mailState').val(thestate);
        }


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        samflex
        wrote on last edited by
        #3

        Thank you for your response sir but it did not work. In other words, the value of WI did not get copied to the mailState DropDownList. I tried hardcoding the State value since that will always be the same like this:

        var thestate = 'WI';
        if (thestate !== "") {
        $('#mailState').val(thestate);
        }

        It appears to change something on the mailState dropdownlist but did not display that WI value in the dropdown. Instead, it showed blank value as the selected value on the mailState dropdownlist box.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups