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
madhu_ramadhu_ra 

Deselect item from apex:inputField with JQuery

I have an apex:inputField in my visualforce page. It is populated with a picklist field of a standard object.

 

<apex:inputField id="practiceselection" value="{!PracticeOpportunity.myPickList__c}" onchange="myOnchangeFunction(this);" ></apex:inputField>

There is one item in this picklist which is the default value. I need to deselect that default item from the component whenever user select one from the list. I tried to do this with JQuery but could not able to overcome. 

This is what I tried finally. When user select more than one with the default value, I tried to deselect all options.

 

$('#practiceselection').val([]);

 But this didn't work. Please give an idea to implement this.

 

Thanks & Regards,

Madhura

 

Avidev9Avidev9

To select a vf component with jquery try this

SF generates Id based on its own algorithm something like "jd1:jdf01:jdf0001:practiceselection" so normal id selector wont work but you can use ends with selector

$('[id$='practiceselection'')
Avidev9Avidev9
By the way you can use actionSupport as well to make the field blank by assigning PracticeOpportunity.myPickList__c = '' from the controller