Copying from billing address to mailing address if they are the same not working correctly
-
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:
-
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:
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
-
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
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.