Skip Navigation

[Resolved] Automatically change a field value when another field is changed

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have a user form that has two fields one is the organization which is (select type) and another for request status which is (Radio type)

I would like to automatically change the field value of the request status field from rejected to pending at any time the organization field is updated.

Solution:

It needs custom JS codes, for example:

https://toolset.com/forums/topic/automatically-change-a-field-value-when-another-field-is-changed/#post-1979199

Relevant Documentation:

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by salimA 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1978041
orgUpdate.JPG

Hi Support,

I have a user form that has two fields one is the organization which is (select type) and another for request status which is (Radio type)
I would like to automatically change the field value of the request status field from rejected to pending at any time the organization field is updated. Check the attached image.
I have displayed the value of the radio only because I don't want the user to change the value.

#1978063

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin.

You might consider custom codes, for example:
1) After user update organization field value, setup JS codes to trigger AJAX call:

2) In the WordPress server side, get the organization field value, and response related result, and update request status field value

More help:
hidden link
https://codex.wordpress.org/AJAX_in_Plugins

For your reference.

#1978071

I appreciate if you Could help me to do it since I am not that much familiar with Ajax and Jquery

#1978121

Please provide a test site with the same problem, also point out the problem page URL and form URL, thanks

#1979199

Thank for the details, I have done below modifications in your website:
Edit the user form "Update User Form readonly":
hidden link

1) in section "Form Editor", add those two fields into form content:
line 46:
[cred_field field="request-status" force_type="field" class="form-control" output="bootstrap"]
line 36:
[cred_field field="org" force_type="field" class="form-control" output="bootstrap"]

You can use CSS codes to hide above "org" field

2) in section "JS Editor", add below codes:

jQuery(document).on('cred_form_ready', function(){
	jQuery( 'select[name="wpcf-org"]' ).change(function() {
        jQuery( 'b.wpcf-request-status' ).text('Pending');
      	jQuery( 'input[name="wpcf-request-status"][value=3]' ).prop("checked",true);;
    });
});

Please test again, check if it is what you want, thanks

#1979381

Many Many thanks yang. your support is highly appreciated. It is working well as I desired.