How to get selected value from 'new' dropdown list in JavaScript

  • 5 April 2017
  • 6 replies
  • 19 views

Userlevel 2
Badge +11

As of Nintex Forms 2013 version 2.9.x the control behaviour of the dropdown list in custom JavaScript has changed. And 'NWF$('#'+ myLookupDropdownList + ' option:selected').text();' doesn't seem to work anymore. How can I get the selected value now from  a choices or list lookup dropdown list?


6 replies

Userlevel 5
Badge +14

does this help   ?

Userlevel 2
Badge +11

Thank you Marian,

But I can't extract the proper info to get it working on my Form, as it is about setting values in the dropdown, seemingly using a textbox control for handling the postback.... Also with regards to the .next('input') snippet, in Edit preview mode, selecting an option seems to leave the next <input> control empty until the form is saved, whereas if I debug an actual form with data the <input> has a value property showing the selected item's lookup value (when changing the selected value, this does not change). As such it's also quite a challenge to figure out alternative jQuery selection option to get hold of the selected value.

So, in my particular case I have a lookup ddl from a Lookup column Currency with JavaScrip id 'jsCurrency'. In this control's change() method I use the following line:

NWF$("#" + jsCurrency).change(function() {

      var selectedCurrency = NWF$('#'+ jsCurrency + ' option:selected').text();

      // Do some more actions with the currency value.

});

What should I use instead to get the value?

NB: It would have been nice if in those cases where updated controls' behavior changes in custom JavaScript, that a document is made available showing the list of affected controls as well as the most common JS snippets for both the old and the new ones.

PS: we're currently testing the upgrade to Forms 2.10. where the above happens.

Badge +4

Hi,

Can you give it a try like this,

NWF$("#" + jsCurrency).change(function() {

      var selectedCurrency = NWF$(this).find("option:selected").text();

});

Hope this helps.

Userlevel 2
Badge +11

Thank you Nagarjuna,

But this also does not seem to work cry.png If nothing works, I may have to revert back to Nintex Forms 2.8.x....

Userlevel 5
Badge +14

if read through the discussion I linked above carefully, you would noticed that they read lookup/dropdown value like follows

NWF$('#'+DDL).val();

note, that lookup value is returned in a form ID;#Text so you might need to parse out ID or text acc. your needs.

eg. to get lookup text value following should work.

NWF.RuntimeFunctions.parseLookup(NWF$('#'+DDL).val(),true);

it worked for me on NF 2.10.0.0

Userlevel 2
Badge +11

Thank you Marian,

This works like a charm. Also, over night the server has been rebooted again (also rebooted after the Nintex forms update 2 days ago)  and that also improved my Nintex Forms preview experience, as well as behavior of the control (yesterday I got an empty string on the .val() method).

Would it be possible in future to have a separate document with a list of controls for which JavaScript behavior has changed? As well as some alternative snippets for common actions (like getting a selected value)?

Reply