Sử dụng thuộc tính onblur để thực thi script khi phần tử mất focus trong HTML. Bạn có thể chạy mã sau để triển khai thuộc tính onblur:
Ví dụ
<!DOCTYPE html>
<html>
<body>
<p>Gõ văn bản bên dưới!</p>
Quốc gia: <input type="text" name="myid" id="myid" onblur="display()">
<script>
function display() {
var str = document.getElementById("myid");
str.value = str.value.toUpperCase();
}
</script>
</body>
</html>