<html>
<head>
<title>capitalize the first letter of string in JavaScript</title>
</head>
<body style="background:lightgray">
<p>Click the button to test:</p>
<button onclick="test()">Capitalize the first letter of string</button>
</br>
<textarea id="edit" style="height:200px;width:240px">
this is a test
</textarea>
<script>
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function test() {
var text=document.getElementById("edit").value;
document.getElementById("edit").value=capitalizeFirstLetter(text);
}
</script>
</body>
</html>
Comments
Post a Comment