cancel
Showing results for 
Search instead for 
Did you mean: 
slothman16
Nintex Newbie

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

Jump to solution

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

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

Labels: (1)
0 Kudos
Reply
4 Replies
lakshminarayana
Nintex Newbie

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

Jump to solution

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

 

Thanks,

Lakshmi Narayana C

0 Kudos
Reply
slothman16
Nintex Newbie

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

Jump to solution

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

0 Kudos
Reply
lakshminarayana
Nintex Newbie

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

Jump to solution

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,

0 Kudos
Reply
slothman16
Nintex Newbie

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

Jump to solution

Thank you Lakshmi

0 Kudos
Reply