Try this. its working well. :-)
<script type="text/javascript">
String.prototype.capsFirst=function() {
return this.substr(0,1).toUpperCase()+ this.substr(1);
}
function doCompareDate() {
var name = document.getElementById("mytext").value;
document.getElementById("mytext").value=name.trim().capsFirst();
}
</script>
example.
http://jsfiddle.net/4F7pH/1/