javascript

ProcessMaker code contributions

Moderator: amosbatto

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

javascript

Unread postby sabinsunny » Wed Mar 29, 2017 9:38 am

Hi Team, Today i need a java script

i have a dropdown list and and a textbox;
i need to display the value in textbox which i select in the dropdown list.

amosbatto
Posts: 5440
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: javascript

Unread postby amosbatto » Wed Mar 29, 2017 5:54 pm

Do you want the value of the selected option in the dropdown or its label?

To copy the value of the selected option, do this:

Code: Select all

$("#mydropdown").setOnchange( function (newVal, oldVal) {
    $("#mytextbox").setValue(newVal);
});

If you need the label of the selected option, then do this:

Code: Select all

$("#mydropdown").setOnchange( function (newVal, oldVal) {
    var aOptions = $("#mydropdown").getInfo().options;
    for (var i in aOptions) {
        if (aOptions[i].value == newVal) {
            $("#mytextbox").setValue(aOptions[i].label);
            break;
        }
    }       
});

Where "mydropdown" is the ID of your dropdown and "mytextbox" is the ID of your textbox.
Import this DynaForm for an example:
get label of selected option.json
(2.31 KiB) Downloaded 26 times
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: javascript

Unread postby sabinsunny » Thu Mar 30, 2017 3:07 am

Hi amosbatto ,
Thank You So Much,

Here i need another coding also

need to take substring from one dropdown box value to another textbox
Attachments
string.png
string.png (1.08 KiB) Viewed 441 times
DropBox.png
dropdownn box
DropBox.png (3.57 KiB) Viewed 441 times

mishika
Posts: 156
Joined: Thu Feb 16, 2017 3:03 am
Country: India

Re: javascript

Unread postby mishika » Thu Mar 30, 2017 5:04 am

Hello,

To add a substring to another text box, you can make a little modification to the code given by Amos.
Code can be as follows:

Code: Select all

$("#mydropdown").setOnchange( function (newVal, oldVal) {
  var aOptions = $("#mydropdown").getInfo().options;
  for (var i in aOptions) {
    if (aOptions[i].value == newVal) {
      $("#mytextbox").setValue(aOptions[i].label);
      var lab = aOptions[i].label;   //take the label
      var res = lab.split("-");      //split and get an array
      $("#mytextbox1").setValue(res[1]);    //assign a value from array to a textbox
      break;
    }
  }
});

You can use .split function to break the string on the basis of a connector like -, ., _ etc.
You can also use .substring function where you will have to pass the starting index and the ending index of the string to be selected from the main string.

Hope this helps

Best Regards
Mishika
Mishika


Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest