cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Solution Supplier
Solution Supplier

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
Solution Supplier
Solution Supplier

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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Users online (7,897)