cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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 @Anonymous,

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 @Anonymous,

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");

Anonymous
Not applicable

Thank you so much @justinburch , it works!

Helpful resources

Announcements
Carousel Community Blog

Check out the Community Blog

Read all about the most recent blogs in the community!

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Carousel News & Announcements

What's New in the Community?

Check out the latest News & Events in the community!

Users online (4,021)