0
<b><a href="#" onClick="clearValue()" > Clear </a> </b>
<script>
function clearValue() {
document.getElementById('{!$Component.page1:form1:input1}').value='';
document.getElementById('{!$Component.page1:form1:selectlist:selectoption}').value='Equal';
}          
</script>

by using this function .i am getting

document.getElementById('{!$Component.page1:form1:input1}').value=' '; 

This set the my inputtextbox to null.

document.getElementById('{!$Component.page1:form1:selectlist:selectoption}').value='Equal';

this is not working with select option . can any body know how to write this one

1

You have to look for the option into your select element and then set it as selected, try:

If you have access to jquery you only have to:

$('#$Component.page1:form1:selectlist').val('Equal');

else:

function clearValue() {
   document.getElementById('{!$Component.page1:form1:input1}').value='';
   setOptionSelected(document.getElementById('{!$Component.page1:form1:selectlist}') ,'Equal');
}        

function setOptionSelected(mySelObj, myValue){
  for(var i=0,sL=mySelObj.length;i<sL;i++){
    if(mySelObj.options[i].text == myValue){
      mySelObj.selectedIndex = i;
      break;
    }
  }
}
0

Try this

document.getElementById('{!$Component.page1.form1.selectlist}').selectedIndex=0;

Where 0 is the index number. If 'Equal' is your 0th, 1st, 2nd... option, then update the index accordingly.

  • This will set only the select on the first option, if the first option is not Equal guess what – Martin Borthiry Feb 13 '14 at 7:38
  • no it is not working – Teja Feb 13 '14 at 7:41
  • @MartinBorthiry of course that is for Teja to figure out what the index should be. Anyway, updated the answer. – AslamK Feb 13 '14 at 7:44
  • yes Equal is my 0th option .still it is not working – Teja Feb 13 '14 at 7:48
  • Oh hey. You are not referencing the component correctly. Its not ':'. Rather you have to use '.'. And I hope the hierarchy of the component is correct, and you are not missing any pageblocks or sections in between. And it should just be till the select list. Updated my answer – AslamK Feb 13 '14 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.