capitalize the first letter of string in JavaScript

<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

Popular posts from this blog

How to write data into a excel file using vbscript

Format date as yyyy-mm-dd using vbscript