cancel
Showing results for 
Search instead for 
Did you mean: 
civilgb
Nintex Newbie

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

Jump to solution

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?

Tags (2)
0 Kudos
Reply
1 Reply
civilgb
Nintex Newbie

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

Jump to solution

I have found the solution:

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

0 Kudos
Reply