# Show/hide field depending on value of other field

**URL:** <https://forum.radsystems.io/t/show-hide-field-depending-on-value-of-other-field/1519>\
**Category:** PHPRad Classic\
**Created:** [April 20, 2023, 12:49pm UTC](https://forum.radsystems.io/t/show-hide-field-depending-on-value-of-other-field/1519 "2023-04-20T12:49:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhavin](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/b/50afbb/32.png) [@bhavin](https://forum.radsystems.io/u/bhavin)\
**Post date:** [April 20, 2023, 12:49pm UTC](https://forum.radsystems.io/t/show-hide-field-depending-on-value-of-other-field/1519/1 "2023-04-20T12:49:03Z")

</div>

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?

To this, I was answered on [phprad.com](http://phprad.com) as follows:  
“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.”

I tried with the following code:

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.

It has been over 4 weeks and nobody seems to be interested out there.

Is there anyone here who can help me out?

Thank you.
