Uppercase Text Input with Javascript


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>

คำสำคัญ (Tags): #javascript#uppercase
หมายเลขบันทึก: 502671เขียนเมื่อ 18 กันยายน 2012 15:37 น. ()แก้ไขเมื่อ 18 กันยายน 2012 15:41 น. ()สัญญาอนุญาต: ไม่สงวนสิทธิ์ใดๆจำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (0)

ไม่มีความเห็น

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท