Page 1 of 1

Select option in dropdown using JavaScript

Posted: Tue May 07, 2019 3:13 pm
by silviuA
Hi,
I have a dropdown control with the id "dropdown1" which is populated from a processmaker table using a sql query like : SELECT client_id, concat(client_name, ' ', client_lastname) FROM PMT_CLIENTS.
In a different text control, with the id "tex1", I obtain the client_id value from the database.

What I want is to use javascript to select the client in "dropdown1" based of the value of "text1".
I tried using :

$("#dropdown1").setValue($("#tex1").getValue());

but is not working, the dropdown1 shows the placeholder, not the client data.

It must be a simple matter because I did not find anything related on the forum or in the wiki, but I just don't know how to solve it. I would appreciate any idea you may have. Thanks.
As an extra info, I'm using Processmaker 3.2.1-community, and my JS skill is kinda low.

Re: Select option in dropdown using JavaScript

Posted: Tue May 07, 2019 11:53 pm
by amosbatto
Your JavaScript code should work, if your "tex1" field contains the ID of one of your clients.

If you export the Dynaform and post the .json file and export the structure your PM Table and post it, then I will look at it.

Re: Select option in dropdown using JavaScript

Posted: Wed May 08, 2019 2:17 am
by silviuA
Hi Amos and thanks for the quick reply.
Upon confirmation that the code should work, I investigated a little and found out that the jQuery plugin "select2" was interfering. I deactivated it for this specific control and everything is working as expected (well except for the fact that it is not showing the placeholder's value when nothing is selected, but that's no biggie).
Thanks again!
Cheers,
Silviu