Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Show/Hide section condition not working

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?
  • tv22 Profile Picture
    tv22 5 on at
    RE: Show/Hide section condition not working

    Thank you, it works fine now.

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Show/Hide section condition not working

    the error is probably this line

    if (value = 1)

    should be

    if (value == 1)

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans