cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
byansakura
Helper III
Helper III

Enable a field upon another field's value

Hey, I was including an entity form here to my web form as additional action and I wanted to disable the field Other University and only enable it when the field Institute Name is set as "Others...". Is there any possible way to add the custom javascript to the entity form to achieve that? Thank you in advance!

byansakura_0-1600406930422.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
justinburch
Microsoft
Microsoft

Hi @byansakura,

In your Entity Form's custom JS, use the below code - update for your actual field schemas.

If you want to clear & hide the value for any selection other than "Other..."

$(function () {
    var $instName = $("#new_institutename);
    $instName.change(function () {
        if ($instName.val() === "1234567") { // use actual option set value for 'Other...'
            $("#new_otheruniversity").closest("td").show();
        } else {
            $("#new_otheruniversity").val("").closest("td").hide();
        }
    }).change();
});

If you want to instead disable it:

$(function () {
    var $instName = $("#new_institutename);
    $instName.change(function () {
        if ($instName.val() === "1234567") { // use actual option set value for 'Other...'
            $("#new_otheruniversity").prop("readonly", false);
        } else {
            $("#new_otheruniversity").val("").prop("readonly", true);
        }
    }).change();
});

 If you don't want to clear the value, you can leave off the .val("") part and just use .prop("readonly", true");

View solution in original post

2 REPLIES 2
justinburch
Microsoft
Microsoft

Hi @byansakura,

In your Entity Form's custom JS, use the below code - update for your actual field schemas.

If you want to clear & hide the value for any selection other than "Other..."

$(function () {
    var $instName = $("#new_institutename);
    $instName.change(function () {
        if ($instName.val() === "1234567") { // use actual option set value for 'Other...'
            $("#new_otheruniversity").closest("td").show();
        } else {
            $("#new_otheruniversity").val("").closest("td").hide();
        }
    }).change();
});

If you want to instead disable it:

$(function () {
    var $instName = $("#new_institutename);
    $instName.change(function () {
        if ($instName.val() === "1234567") { // use actual option set value for 'Other...'
            $("#new_otheruniversity").prop("readonly", false);
        } else {
            $("#new_otheruniversity").val("").prop("readonly", true);
        }
    }).change();
});

 If you don't want to clear the value, you can leave off the .val("") part and just use .prop("readonly", true");

View solution in original post

Thank you so much @justinburch , it works!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Users online (20,696)