Clear the managed metadata control using JavaScript

  • 19 December 2017
  • 3 replies
  • 2 views

Badge +2

I have a Managed Metadata Control that I want to clear whenever a checkbox is unchecked.

Managed Metadata control

Client ID JavaScript variable name for the checkbox is 'fldCheckBox'

Client ID JavaScript variable name for the Managed Metadata control is 'fldMetaData'

I am using the following code -

 NWF$(document).ready(function()
{  

      NWF$('#'+ fldCheckBox).change(function()
     {
          if(NWF$('#' + fldCheckBox).prop('checked') == false)
          {
               NWF$('#' + fldMetaData).val('');
          }
     });   

});

I am able to get into the change event and into the if block as well.

 

However the following statement is not making the desired effect.

NWF$('#' + fldMetaData).val('');

Could somebody please help me with a JavaScript to clear this metadata control, whenever the checkbox is unchecked.

I would appreciate any help extended to me.

Thanks.


3 replies

Badge +9

It should work. Try below code (instead 'Change', try with 'Click' event).

NWF$(document).ready(function()
{  

   NWF$('#' + fldCheckBox).click(function()
   {
     var checkBox = NWF$('#' + fldCheckBox);
     if (checkBox.is(':checked') == false)

     {

       NWF$('#' + fldMetaData).val('');
     }

   });
});

Badge +2

Hi Lakshmi,

It did not work.

The problem is not with the change event. I am able to get into the change event and into the if block as well.

The problem is that the statement " NWF$('#' + fldMetaData).val('');" is not making the desired effect.

Thanks.

Badge +7

Hi Ritesh,

Try using NWF$('#' + fldMetaData).text('');

In one of my environment this helped in updating the metadata field.

Thanks,

Soni

Reply