web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Show/Hide section condition not working

(0) ShareShare
ReportReport
Posted on by 5

Hello,

I've been working on a JavaScript webresource which shows/hides sections based on checkbox being checked/unchecked. The checkbox appears to be working fine on the first click, but afterwards, however, it just keeps returning "yes" alerts no matter if checked or unchecked.

function onchange(context) {
  var formContext = context.getFormContext();
  var value = formContext.getAttribute('my_field').getValue();
  var tabsectformContext.ui.tabs.get("my_tab");

  if (value = 1)
  {
       tabsect.sections.get('tab_9_section_2').setVisible(true);
       alert ("yes");
  }
  else  {
       tabsect.sections.get('tab_9_section_2').setVisible(false);
       alert ("no");
  }
   formContext.data.refresh(true);
  }
Above is a snippet of my code. Whatever I do with the code, it either returns an error or just keeps returning "yes" alerts as it is stuck. Any suggestions?
I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    the error is probably this line

    if (value = 1)

    should be

    if (value == 1)

    equals in JavaScript needs to have 2 equals sign (==)

  • tv22 Profile Picture
    5 on at

    Thank you, it works fine now.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans