Solved

Nintex Forms. JavaScript: set value to dropdown control by Text.

  • 22 November 2018
  • 1 reply
  • 751 views

Badge +2

I need to set by JavaScript a value to a dropdown field control knowing only Text.

For example, There is a dropdown control that has 3 values - One, Two, Three. I need to set my value to Three by JavaScript. I found that aricle Custom Script on O365 and according to this I can set value only knowing Id, but I want set value not by Id but by Text.

 

That works:

  1. NWF.FormFiller.Events.RegisterAfterReady(function () {  
  2.     NWF$('#' + ddlStaff).on('change'function (e) {  
  3.         if (e.originalEvent == undefined) {  
  4.             if (this.value == "") {  
  5.                 this.value = "1";  
  6.             }  
  7.         }  
  8.     });  
  9. });

 

But like this it does not work:

  1. NWF.FormFiller.Events.RegisterAfterReady(function () {  
  2.     NWF$('#' + ddlStaff).on('change'function (e) {  
  3.         if (e.originalEvent == undefined) {  
  4.             if (this.value == "") {  
  5.                 this.value = "Three";  
  6.             }  
  7.         }  
  8.     });  
  9. });

Any ideas how to set value by Text?

icon

Best answer by civilgb 23 November 2018, 08:39

View original

1 reply

Badge +2

I have found the solution:

NWF$("#" + ddlStaff + " option:contains(" + Three +")").attr("selected", true);  

Reply