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
SF Buzz VutukuriSF Buzz Vutukuri 

How to clear the values of text box on button click

HI,
Please say me the way to clear the values in the textbox  on button click .......

I've tried like  
<apex:form id="fromA">
<apex:inputext value="{!a}" Id="txt"/>
<apex:commandbutton value="clear" onClick="clearfun()"/>
</apex:form>
<script>
 function clearfun()
{
 // document.formA.[txt]= " ";
 or
document.getElementbyid("txt").value=" ";
}
</script>

but the above code isn't working :(

Best Answer chosen by SF Buzz Vutukuri
bob_buzzardbob_buzzard
I've just checked the link and its working fine.

I can't correct your code as the ID will be dependent  on the location of the element inside the page.  This is explained in more detail at:

https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm

If you figure it out yourself you'll know how to fix this the next time you encounter it.

All Answers

bob_buzzardbob_buzzard
You have a couple of issues :

1. You need to return false from your onclick handler or the form will be submitted and the page will be refreshed.
2. You aren't identifying the input element correctly - I've gone into this in more detail at:

http://bobbuzzard.blogspot.co.uk/2014/07/component-vs-selectors.html
SF Buzz VutukuriSF Buzz Vutukuri
@bob_buzzard - Hi I've tried to open 'http://bobbuzzard.blogspot.co.uk/2014/07/component-vs-selectors.html' this link but it is not working, could be please correct the code for me
bob_buzzardbob_buzzard
I've just checked the link and its working fine.

I can't correct your code as the ID will be dependent  on the location of the element inside the page.  This is explained in more detail at:

https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm

If you figure it out yourself you'll know how to fix this the next time you encounter it.
This was selected as the best answer
SF Buzz VutukuriSF Buzz Vutukuri
@bob_buzzard - thank you :) got it now it is working fine