Skip to main content

Hello,

The functionality I am trying to replicate is similar to when you have the option to select "same as billing address" when ordering something online to use as the shipping address

I have found this article but I am not familiar with javascript, however there is some confusion about the name of the fields used in the screen shots and the names in the script. Below are my screenshots of the fields and controls involved and the script I am using. I am trying to test with the ShipToAddress and Ctiy to be copied to BillToAddress and City when check box is ticked.

Thanks

205479_pastedImage_2.png

205480_pastedImage_3.png

205481_pastedImage_4.png

205482_pastedImage_5.png

205483_pastedImage_6.png

NWF$('#' + Same).click(function(){
  var checkBox = NWF$('#' + varSame);
  if (checkBox.is(':checked') == true){
  var ShipToAddress = NWF$('#' + varShipToAddress).val();
  var ShipToCity = NWF$('#' + varShipToCity).val();
  NWF$('#' + varBillToAddress).val(ShipToAddress);
  NWF$('#' + varBillToCity).val(ShipToCity);
  }
  else
  {
  var nullValue = '';
  NWF$('#' + varBillToAddress).val(nullValue);
  NWF$('#' + varBillToCity).val(nullValue);
  }
});

Hi Andrew Slee‌,

The entire code is perfect but only change was, use javascript variable name of yes/no check box control to call on click function instead of its name.

NWF$('#' + varSame).click(function()
{
  var checkBox = NWF$('#' + varSame);
  if (checkBox.is(':checked') == true){
  var ShipToAddress = NWF$('#' + varShipToAddress).val();
  var ShipToCity = NWF$('#' + varShipToCity).val();
  NWF$('#' + varBillToAddress).val(ShipToAddress);
  NWF$('#' + varBillToCity).val(ShipToCity);
  }
  else
  {
  var nullValue = '';
  NWF$('#' + varBillToAddress).val(nullValue);
  NWF$('#' + varBillToCity).val(nullValue);
  }
});

205495_pastedImage_2.png 205499_pastedImage_3.png

Thanks,

Lakshmi Narayana C


Thank you Lakshmi. Is it possible to also hide the fields when the checkbox is checked, or add them to a panel and hide that. Let me know if this should be a different post

Thanks again


Hi Andrew Slee‌,

Try with this.

NWF$(document).ready(function(){  
  fnChangeCheckBox();
NWF$('#' + varSame).click(function()
{
 fnChangeCheckBox();
});
   NWF$('#' + varBillToCity).hide();
 NWF$('#' + varBillToAddress).hide();
});
function fnChangeCheckBox()
{
  var checkBox = NWF$('#' + varSame);
  if (checkBox.is(':checked') == true){
  var ShipToAddress = NWF$('#' + varShipToAddress).val();
  var ShipToCity = NWF$('#' + varShipToCity).val();
  NWF$('#' + varBillToAddress).val(ShipToAddress);
  NWF$('#' + varBillToCity).val(ShipToCity);
  NWF$('#' + varBillToCity).show();
 NWF$('#' + varBillToAddress).show();
  }
  else
  {
  var nullValue = '';
  NWF$('#' + varBillToAddress).val(nullValue);
  NWF$('#' + varBillToCity).val(nullValue);
  NWF$('#' + varBillToCity).hide();
 NWF$('#' + varBillToAddress).hide();
  }
}

Thanks,


Thank you Lakshmi


Reply