Skip to main content
Nintex Community Menu Bar

Auto-populate form fields based on data in other fields when a checkbox is selected

  • July 11, 2017
  • 4 replies
  • 20 views

Forum|alt.badge.img+3

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);
  }
});

4 replies

Forum|alt.badge.img+9

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


Forum|alt.badge.img+3
  • Author
  • July 12, 2017

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


Forum|alt.badge.img+9

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,


Forum|alt.badge.img+3
  • Author
  • July 21, 2017

Thank you Lakshmi