JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Document created by nidish.kotian Expert on Sep 25, 2014Last modified by nidish.kotian Expert on Feb 8, 2016
Version 2Show Document
  • View in full screen mode


Consider a List/Task/Workflow start form, where in the form contains a list look up control and a single line control. The list look up control is mandatory field and if user selects one particular value in the look up, the single line field will become mandatory.



The list lookup control fetches values from list called, ‘Country’. Consider the items in the list ‘Country’ are:

  1. India
  2. Australia
  3. UK
  4. USA
  5. Others

If the user selects ‘Others’ then the single line control should be made as mandatory field. One of the ways to achieve this functionality is by using custom JavaScript validation



Step 1: Consider that the form resemble as shown in the below screenshot:



Step 2: Go to the settings of the lookup control and in the advanced section, set ‘Store Client ID in JavaScript variable’ to ‘Yes’ and give a valid variable name as shown below



Step 3: Go the setting of the single line control and in the validation section set ‘Use custom validation’ to Yes and provide the ‘Custom validation function’ name and the valid ‘Custom error message’


Step 4: Now to go to form setting from the top ribbon and navigate to Custom JavaScript tab


Step 5: Add this function in the Custom JavaScript function

//Check if Country name is mentioned

function CheckIfOtherCountry(source, arguments) {

try {

        var selectedCountry = NWF$("#" + ddlPicker+ 'option:selected');

        var selectedCountryValue = selectedCountry.text();

        arguments.IsValid = true;

        if (selectedCountryValue == "Others") {

                arguments.IsValid = false;



catch (err) {




That’s it. You form is ready to go!!!   


Thanks to Prajna Priyadarshini for providing valuable suggestions for this document.

1 person found this helpful