A simple program in JavaScript that shows how to use focus method in a program. The code is very basic and easy to understand for beginners that are new in JavaScript programming.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.
Program Listing
<html>
<head>
<title> Focus method in JavaScript</title>
<head>
<h1> Focus Method in JavaScript </h1>
<br>
<body>
<input type="text" id="txtName"/>
<input
type = "button"
id = "btnCompute"
onclick = "Compute();"
value = "Compute"/>
</body>
<script>
function Compute() {
var txtName = document.getElementById("txtName");
var name = txtName.value;
if (name.trim() == "") {
alert("Please enter value for name. ");
txtName.focus;
} else {
alert("Hello " + name + " ! ");
}
}
</script>
</html>
No comments:
Post a Comment