Skip to main content
added 79 characters in body
Source Link
Ashwani
  • 22.7k
  • 4
  • 41
  • 73

First thing is when you upload a javascript function which bind a expression using visualforce way. It would not work. Visualforce only renders expressions when they are on page.

document.getElementById('{!$Component.page1:form1:autocomplete1}').value=''; on page will work but in static resource as a part of javascript file won't work. You will find it as it is written.

Using jquery referencing a visualforce element is easy bit not in javascript. For this you have to use classes to reference the element.

Sample Example:

You have a select option (using class name to reference)

<apex:selectList id="firstuser_right" styleclass="autocomplete1" value="{!SelectedAvailableFields}" multiselect="true" size="5">
   ....
</apex:selectList>

You can get/set the value of the element as:

document.getElementsByClassName('autocomplete1')[0].value='';

This would work on visualforce page as well as in static resource javascript file. Use jquery to make changes in bulk. This would save time of execution.

In jquery you can clear all values like this:

$(".myClass").val('');

First thing is when you upload a javascript function which bind a expression using visualforce way. It would not work. Visualforce only renders expressions when they are on page.

document.getElementById('{!$Component.page1:form1:autocomplete1}').value=''; on page will work but in static resource as a part of javascript file won't work. You will find it as it is written.

Using jquery referencing a visualforce element is easy bit not in javascript. For this you have to use classes to reference the element.

Sample Example:

You have a select option (using class name to reference)

<apex:selectList id="firstuser_right" styleclass="autocomplete1" value="{!SelectedAvailableFields}" multiselect="true" size="5">
   ....
</apex:selectList>

You can get/set the value of the element as:

document.getElementsByClassName('autocomplete1')[0].value='';

This would work on visualforce page as well as in static resource javascript file. Use jquery to make changes in bulk. This would save time of execution.

First thing is when you upload a javascript function which bind a expression using visualforce way. It would not work. Visualforce only renders expressions when they are on page.

document.getElementById('{!$Component.page1:form1:autocomplete1}').value=''; on page will work but in static resource as a part of javascript file won't work. You will find it as it is written.

Using jquery referencing a visualforce element is easy bit not in javascript. For this you have to use classes to reference the element.

Sample Example:

You have a select option (using class name to reference)

<apex:selectList id="firstuser_right" styleclass="autocomplete1" value="{!SelectedAvailableFields}" multiselect="true" size="5">
   ....
</apex:selectList>

You can get/set the value of the element as:

document.getElementsByClassName('autocomplete1')[0].value='';

This would work on visualforce page as well as in static resource javascript file. Use jquery to make changes in bulk. This would save time of execution.

In jquery you can clear all values like this:

$(".myClass").val('');
Source Link
Ashwani
  • 22.7k
  • 4
  • 41
  • 73

First thing is when you upload a javascript function which bind a expression using visualforce way. It would not work. Visualforce only renders expressions when they are on page.

document.getElementById('{!$Component.page1:form1:autocomplete1}').value=''; on page will work but in static resource as a part of javascript file won't work. You will find it as it is written.

Using jquery referencing a visualforce element is easy bit not in javascript. For this you have to use classes to reference the element.

Sample Example:

You have a select option (using class name to reference)

<apex:selectList id="firstuser_right" styleclass="autocomplete1" value="{!SelectedAvailableFields}" multiselect="true" size="5">
   ....
</apex:selectList>

You can get/set the value of the element as:

document.getElementsByClassName('autocomplete1')[0].value='';

This would work on visualforce page as well as in static resource javascript file. Use jquery to make changes in bulk. This would save time of execution.