You need to sign in to do that
Don't have an account?

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 :(
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
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
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.