cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

How do I reset a dropdown value?

Jump to solution

Hello!

I have 2 dropdown fields.

First dropdown contains a list of numerical codes.

Second list contains another list of numerical codes.

If the selected value for first dropdown does not equal to say 1000, 2000, 3000, or 4000, the second dropdown needs to be reset to "Please select a value..." (Nintex's default value).

I've looked up several JavaScript examples but they all don't work. Can someone please help?

Tags (2)
0 Kudos
Reply
8 Replies
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

You can use Custome JavaScript for this:

  1. Set JavaScript variable for the 2 dropdown controls. For ex ddl1 and ddl2
  2. Use the below code in the Custome JavaScript of the Form Settings

var ddlNumericalCode1 = NWF$("#" + ddl1);
ddlNumericalCode1.change(function()
{
if(ddlNumericalCode1.find("option:selected").text()!="1000" || ddlNumericalCode1.find("option:selected").text()!="2000" ddlNumericalCode1.find("option:selected").text()!="3000" || ddlNumericalCode1.find("option:selected").text()!="4000")
{

var ddlNumericalCode2 =NWF$('#' + ddl2 + ' option:contains(Please select a value...)');
var ddlNumericalCode2Value = ddlNumericalCode2.val();
ddlNumericalCode2.prop('selected','selected');

NWF$('#' + ddl2).parent().find('input').val(ddlNumericalCode2Value);
NWF.FormFiller.Functions.ProcessOnChange(ddlNumericalCode2);

}

}

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

Hi Chaitra

Thanks for your help! I tried the following but it didn't work. What could be wrong?

Note:

1. My ddl1 = CostCentre, ddl2=RegionalCode

2. I noticed you had a "||" missing from the condition and added it.

3. My first dropdown is a list lookup.

var ddlCostCentre = NWF$("#" + CostCentre);

ddlCostCentre.change(function()

{

if(ddlCostCentre.find("option:selected").text()!="2;#3750" || ddlCostCentre.find("option:selected").text()!="17;#3751" || CostCentre.find("option:selected").text()!="18;#3760" || ddlCostCentre.find("option:selected").text()!="27;#4250")

{

var ddlRegionalCode =NWF$('#' + RegionalCode + 'option:contains(Please select a value...)');

var ddlRegionalCodeValue = ddlRegionalCode.val();

ddlRegionalCode.prop('selected','selected');

NWF$('#' + RegionalCode).parent().find('input').val(ddlRegionalCodeValue);

NWF.FormFiller.Functions.ProcessOnChange(ddlRegionalCode);

}
}

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

In case of list lookup column can you confirm using the browser developer tool what the below code returns:

NWF$("#" + CostCentre).find("option:selected").text()

Also check is any errors occur on the code which you have shared(using browser developer tool)

NOTE: replace CostCentre.find("option:selected").text()!="18;#3760" with ddlCostCentre.find("option:selected").text()!="18;#3760" in your code

Please share your outcome.

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

Hi Chaitra,

Both CostCentre and RegionalCode are returning empty values in the developer tool. They're both list lookups, any issues with this?

but this works:

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

Yes, it works different for a List Lookup field.

Check this https://community.nintex.com/message/60434-re-set-a-field-value-with-a-list-lookup-control?commentID...  for more information.

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

This works

NWF$(document).ready(function () {

var CostCentreDDL = NWF$('#' + CostCentre);

function setRegionalCodeLookupValue(RegionalCode, value) {
NWF$(NWF$('#' + RegionalCode).siblings('select')[0]).val(NWF.RuntimeFunctions.parseLookup(value, true));
NWF$('#' + RegionalCode).val(value);
}
CostCentreDDL.change(function () {
var CostCentreValue = CostCentreDDL.val();
var CostCentreParsedValue = NWF.RuntimeFunctions.parseLookup(CostCentreValue,true);
if (CostCentreParsedValue != "3750" && CostCentreParsedValue != "3751" && CostCentreParsedValue != "3760" && CostCentreParsedValue != "4250") {
setRegionalCodeLookupValue(RegionalCode, ';#**SelectValue**');
}
})
})

Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

Anybody can assist for the following:

IF the TransferStatus is select / set to External

THEN reset CostCentre to its default (Select...)

*this should not cause an issue if the CostCentre is already set to Select... but in case is different then reset it.

0 Kudos
Reply
Workflow Hero

Re: How do I reset a dropdown value?

Jump to solution

function setRegionalCodeLookupValue(RegionalCode, value) {
NWF$(NWF$('#' + RegionalCode).siblings('select')[0]).val(NWF.RuntimeFunctions.parseLookup(value, true));
NWF$('#' + RegionalCode).val(value);
}

This part is exactly what I needed for my purposes. Thanks!

0 Kudos
Reply