This javascript will convert lower case letters to uppercase when user input text. It works with IE, Chrome, and Firefox.
<html>
<head>
<title>Uppercase Text</title>
</head>
<script language='javascript'>
function CheckEnter(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13) ValidateInput();
}
function trim(str) { return str.replace(/^\s+|\s+$/g,""); }
function ValidateInput() {
var o = document.getElementById("my_input");
if (trim(o.value) == "") {
alert("Please input some text");
o.value = "";
o.focus();
return;
}
alert("Your input: " + o.value + "\nUppercase: " + o.value.toUpperCase());
}
</script>
<body>
Input: <input name="my_input" id="my_input" type="text" style="text-transform:uppercase;" onkeypress="CheckEnter(event)"/>
Note: Input some text and press enter key
</body>
</html>
ไม่มีความเห็น