Convert first letter to uppercase on Input box

Convert first letter to uppercase on Input box

<html>
<head>
<title>Convert first letter to uppercase on Input box</title>
<script type=”text/javascript”>
function capitalize(textboxid, str) {
// string with alteast one character
if (str && str.length >= 1)
{
var firstChar = str.charAt(0);
var remainingStr = str.slice(1);
str = firstChar.toUpperCase() + remainingStr;
}
document.getElementById(textboxid).value = str;
}
</script>
<body>
<form name=”myform” method=”post”>
<strong>Capitalize :</strong>
<input type=”text” id=”mytextbox” onkeyup=”javascript:capitalize(this.id, this.value);”>
</form>
</body>
</html>

Do you have any queries?

This site uses Akismet to reduce spam. Learn how your comment data is processed.