Auto populate value in drop-down menu


Badge +7

Hi

I want to auto-select field values based on values elsewhere in the form.

============================

Example:

Drop-down menu A: Creature

Choices: Man, Dog, Spider

Drop-down menu B: Species

Choices: Human, Canine, Arachnid

When a user selects Man in menu A,  menu B auto-populates as Human. 

When a user selects Dog in menu A,  menu B auto-populates as Canine. 

When a user selects Spider in menu A,  menu B auto-populates as Arachnid. 

=============================

These menu choices are not based on lookups of other lists. Using lookup lists is not practical for us. We need our forms in one list without the requirement of maintaining supporting lists.

I understand that InfoPath allows this functionality quite easily, but can't seem to find something similar in Nintex Forms.

I don't mind using JavaScript, just not sure if this can be done without in the latest version or how I would go about doing it. 

Appreciate any help that can be offered.

Platform: Nintex Forms 2013 2.10.1.0

Environment SharePoint 2013 Enterprise


16 replies

Userlevel 5
Badge +13

Do these two threads give you a good starting point?

How to set default value some option in drop down list look up using JQuery or Javascript 

 

Userlevel 5
Badge +14

here is very similar case -  

Badge +7

Thanks for the links but they don't really answer my question. I don't want to auto populate fields when the form is opened. I want to create a link between values in two drop-down menus. Selecting one value in menu A changes the value in menu B, dynamically, while the form is open.

Userlevel 5
Badge +13

Hi Harry,

Marian's link goes specifically into how to modify the value of one field with the event being the change of another. The two links I provided give more details on how to set a dropdown field using Javascript. You can use both of these to create the solution you're looking for. 

You can also check out this resource: How to Create Cascading Choice Controls – Nintex Forms  from

Userlevel 5
Badge +14

here is the script which (re)sets value of dropdown control (choice) based on value of other dropdown control (choice as well).

second control follows each change of the first one. if first control is set to a value out of defined list, second control is cleared.

jsDDA_Creature and jsDDB_Species are javascript variables configured for respective controls.

the script should be placed into form settings >> Custom JavaSript

NWF.FormFiller.Events.RegisterAfterReady(function () {  
    NWF$('#'+jsDDA_Creature).change(function(evt){
        switch(evt.target.value){
            case 'Man' :
                NWF$('#'+jsDDB_Species).val('Human');
                break;
            case 'Dog':
                NWF$('#'+jsDDB_Species).val('Canine');
                break;
            case 'Spider':
                NWF$('#'+jsDDB_Species).val('Arachnid');
                break;
            default:
                //no creature
                NWF$('#'+jsDDB_Species).val('');
                break;
         }
    })
})
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

choice‌ dropdown‌ choice dropdown dropdown choice set dropdown value by other dropdown set choice value by other choice populate dropdown populate choice

Badge +7

Thank you very much for your effort Marian but I can't get that to work. The values are not changing.

I put the script in the form settings custom Javascript section and gave the drop-down menus variable names in their respective settings (store client id in javascript variable). 

Am I missing something else?

Userlevel 5
Badge +14

can you check developer console for any errors?

press F12 in browser, in window that opens switch to 'Console' tab, return to browser and run the form. watch dev console whether there are not any errors reported.

Badge +7

I checked it yes and it said jsDDA_Creature is undefined.

I can't tell what's nintex wrap code and what's not.  Is the jsDDA and jsDDB some type of Nintex code or wrapper or just an example variable name that I can change?

Badge +7

OK it's working after I added the jsDDA and jsDDB to the respective control names. 

Many thanks for your help on this. Apologies I 'm such an amateur at JS. Hopefully I can improve soon but getting to the level above may take some time happy.png

Badge +7

Is there a reference guide for nintex JavaScript code requirements like wrapping code?

Badge +7

If I want to repeat this for other controls on the form can I repeat the code beneath the existing one but change the variable names and names of the controls?

Userlevel 5
Badge +14

In principle yes.

In fact it's enough if you 'repeat' just body of RegisterAfterReady function. But if you 'repeat' whole block nothing wrong happens. Note however, that different type of controls might need to be set  different ways

Userlevel 5
Badge +13

Handy solution.  I was having trouble getting this to work in Nintex Forms 2013 at first, but I finally figured it out.  I had to add a semicolon (;) at the end of the added code after the last }) in the Custom JavaScript.

Userlevel 5
Badge +14

yeah, sometimes nintex loses line feeds at the end of custom code, especially if you copy & paste piece of code, and places follow up code right after the closing bracket. javascript engine has then problems to parse it. so one have to go to the custom code once again and append few of them.

Badge +9

Hi Marian

Will this work for list lookup dropdown lists, in a repeating section? I tried it and it didn't work.

Userlevel 5
Badge +14

Hi ‌,

generally yes.

but this script needs to be tweaked to address control(s) in a proper repeater row(s).

Reply