function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suresh.csksuresh.csk 

Disabling Multi PickList Values

Hi.

 

How to disable a multi picklist when Yes or No Option is selected.

 

If  "Yes" option is selected the multi picklist is enabled.

If  "No" option is selected the multi picklist is diaabled.

 

Here is my code

 

<apex:page controller="myTestController">
<script type="text/javascript">
     
    function getActive(selectedValue)
    {  
    if( selectedValue == 'YES')
    {
    var ele=document.getElementById('{!$Component.form1.dropdown}');
    ele.diasabled = false;  
    }else if(selectedValue == 'NO')
    {
         var ele=document.getElementById('{!$Component.form1.dropdown}');
      ele.disabled =true;
    }
          
    }
</script>

 

 <apex:form id="form1">
        <apex:selectRadio value="{!selectedValue}" layout="pageDirection" onchange="getActive(this.value);">

 

            <apex:selectOption itemValue="YES" itemLabel="YES"/>
            <apex:selectOption itemValue="NO" itemLabel="No"/>
            </apex:selectRadio><p/>


            <apex:inputField value="{!objB.Fruits__c}" id="dropdown" />
  </apex:form>
</apex:page>

 

 

Note:

When refering the ID tried also _unselected but not working.

 

cheers

suresh

 

Best Answer chosen by Admin (Salesforce Developers) 
suresh.csksuresh.csk

Hi.

I figured out and fixed it.

VF:

<apex:form id="form1">
<apex:outputLabel value="Select Check box"/>
<apex:inputCheckbox value="{!mycheckBox}" onclick="dispfun(this);" id="checkbox"/>

<apex:inputField value="{!objB.Fruits__c}" id="dropdown" />
</apex:form>
</apex:page>

In the above example:

1.If I select the checkbox the mutlipicklist should be disabled.

2.When un-check the checkbox the multipicklist should be enabled.

The most chanlleging part is to disabling and enabling  the the right anf left arrow buttons in the multi picklist.

 

To disable the right and left arrow actions ie to diable the "href" of right and left arrow as follows:

Created  a new attribute "name"  and stored the href values in the "name" attribute and

deleted the href attribute.

 

To enable the right and left arrow actions ie to enable the "href" of right and left arrow as follows:

Created  a new attribute "href"  and set the  href values which are stored in the "name" attribute and

deleted the name attribute.

Note:

In multipicklist there is no name attribute,I used name attribute to stored the href values.

 

<script>

function dispfun(selectedValue){
  var selects = document.getElementsByTagName("select");
  var images = document.getElementsByTagName("img");
 

//action when checkbox is selected
  if(selectedValue.checked){

    for (var i = 0; i < selects.length; i++) {

        var checkStr =selects[i].id;
        if(checkStr.match('dropdown_unselected') || checkStr.match('dropdown_selected') )
        {     
        selects[i].disabled = true;
        }
    }
     for (var i = 0; i < images.length; i++) {

        var checkStr =images[i].id;
        var rt =images[i];
        if(checkStr.match('dropdown_right_arrow')){
               
        var temp = images[i].parentNode;
        
        temp.setAttribute('name',temp);
        temp.removeAttribute("href");
        }else if(checkStr.match('dropdown_left_arrow')){
        var temp = images[i].parentNode;
        temp.setAttribute('name',temp);
        temp.removeAttribute("href");
        }
        }
  }

else{ //action when checkbox is un-selected

      for (var i = 0; i < selects.length; i++) {

        var checkStr =selects[i].id;
        if(checkStr.match('dropdown_unselected') || checkStr.match('dropdown_selected') )
        {
               selects[i].disabled = false;
        }
    }
 
     for (var i = 0; i < images.length; i++) {

        var checkStr =images[i].id;
        var rt =images[i];

        if(checkStr.match('dropdown_right_arrow')){
        var temp = images[i].parentNode;
        if(temp.name != null &&  temp.name != ''){
        temp.setAttribute("href",temp.name);  
        temp.removeAttribute("name");
        }
        
        }else if(checkStr.match('dropdown_left_arrow')){
        var temp = images[i].parentNode;
        if(temp.name != null &&  temp.name != ''){
        temp.setAttribute("href",temp.name);  
        temp.removeAttribute("name");
        }
        }
    }  
 
  }
      
}

</script>

 

cheers

suresh

 

All Answers

suresh.csksuresh.csk

Hi.

I figured out and fixed it.

VF:

<apex:form id="form1">
<apex:outputLabel value="Select Check box"/>
<apex:inputCheckbox value="{!mycheckBox}" onclick="dispfun(this);" id="checkbox"/>

<apex:inputField value="{!objB.Fruits__c}" id="dropdown" />
</apex:form>
</apex:page>

In the above example:

1.If I select the checkbox the mutlipicklist should be disabled.

2.When un-check the checkbox the multipicklist should be enabled.

The most chanlleging part is to disabling and enabling  the the right anf left arrow buttons in the multi picklist.

 

To disable the right and left arrow actions ie to diable the "href" of right and left arrow as follows:

Created  a new attribute "name"  and stored the href values in the "name" attribute and

deleted the href attribute.

 

To enable the right and left arrow actions ie to enable the "href" of right and left arrow as follows:

Created  a new attribute "href"  and set the  href values which are stored in the "name" attribute and

deleted the name attribute.

Note:

In multipicklist there is no name attribute,I used name attribute to stored the href values.

 

<script>

function dispfun(selectedValue){
  var selects = document.getElementsByTagName("select");
  var images = document.getElementsByTagName("img");
 

//action when checkbox is selected
  if(selectedValue.checked){

    for (var i = 0; i < selects.length; i++) {

        var checkStr =selects[i].id;
        if(checkStr.match('dropdown_unselected') || checkStr.match('dropdown_selected') )
        {     
        selects[i].disabled = true;
        }
    }
     for (var i = 0; i < images.length; i++) {

        var checkStr =images[i].id;
        var rt =images[i];
        if(checkStr.match('dropdown_right_arrow')){
               
        var temp = images[i].parentNode;
        
        temp.setAttribute('name',temp);
        temp.removeAttribute("href");
        }else if(checkStr.match('dropdown_left_arrow')){
        var temp = images[i].parentNode;
        temp.setAttribute('name',temp);
        temp.removeAttribute("href");
        }
        }
  }

else{ //action when checkbox is un-selected

      for (var i = 0; i < selects.length; i++) {

        var checkStr =selects[i].id;
        if(checkStr.match('dropdown_unselected') || checkStr.match('dropdown_selected') )
        {
               selects[i].disabled = false;
        }
    }
 
     for (var i = 0; i < images.length; i++) {

        var checkStr =images[i].id;
        var rt =images[i];

        if(checkStr.match('dropdown_right_arrow')){
        var temp = images[i].parentNode;
        if(temp.name != null &&  temp.name != ''){
        temp.setAttribute("href",temp.name);  
        temp.removeAttribute("name");
        }
        
        }else if(checkStr.match('dropdown_left_arrow')){
        var temp = images[i].parentNode;
        if(temp.name != null &&  temp.name != ''){
        temp.setAttribute("href",temp.name);  
        temp.removeAttribute("name");
        }
        }
    }  
 
  }
      
}

</script>

 

cheers

suresh

 

This was selected as the best answer
DellaStreetDellaStreet

This was a tremendous help!

Thanks a lot.