Skip to main content
Topic: Show/hide field depending on value of other field (Read 1342 times) previous topic - next topic

Show/hide field depending on value of other field

Hello everyone,

I need to show/hide fields depending on the selection of a previous value …

Example:
Table: Member
mem_id,
mem_name
mem_gender
mem_maritalstatus
mem_anniversarydate
mem_address
mem_areaid


When selecting "Married" in mem_maritalstatus, it should show mem_anniversarydate (as required field) and if in mem_maritalstatus "Unmarried" is selected, it should hide mem_anniversarydate. If the status is edited from "Married" to "Unmarried" the mem_anniversarydate should be cleared.

Secondly, I want to show data from other table in Add/Edit mode. Custom fields are disabled in Add/Edit mode.

Eg:
Table: Area
area_id
area_name
area_zip
area_state

Table: Member
mem_id,
mem_name
mem_gender
mem_maritalstatus
mem_anniversarydate
mem_address
mem_areaid

I'm storing the mem_areaid from area table and need to show the corresponding city and zip of the area as well in the Member table when adding/editing data.

How can this be done?

Thank you.



Re: Show/hide field depending on value of other field

Reply #1
Use Add Page Field Properties -> ClientEvents to write jQuery code to help you archive that. Double clicking on one of the samples on the left panel should show you sample jQuery codes. Archiving this requires you have a knowledge of jQuery.

 

Re: Show/hide field depending on value of other field

Reply #2
Your short answer was tried and tested but it does not seem to work as required.

$('#ctrl-mem_maritalstatus').on('change', function(){
   
   if($(this).val() == 'MARRIED') {
            $('#ctrl-mem_anniversarydate').show();
            $('#ctrl-mem_children').show();
        }
        else {
            $('#ctrl-mem_anniversarydate').hide();
            $('#ctrl-mem_children').hide();
        }
   
});

This code hides the mem_children field when 'MARRIED' status is selected. The label is still visible.

What needs to be done is:

1) When the form loads, the mem_anniversarydate and mem_children along with the respective labels should be hidden. They should only be visible when the option in mem_maritalstatus is selected as 'MARRIED' and they should be set as required field.

2) The second question regarding custom fields in Add/Edit forms is still unanswered.

Please help.