A simple program that we ask the name of the user and then our program will greet the user using JavaScript. The code is very simple and easy for beginners in JavaScript programming.
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
<html>
<head>
<title> Gretter Program </title>
</head>
<style>
body {
font-family:arial;
font-size:16px;
}
</style>
<script type="text/javascript">
function user_name () {
var txtName = form.txt_name.value;
var message = "Hello " + "<b>"+ txtName +"</b>"+ " How are you today?";
document.getElementById("user").innerHTML = message;
}
function clear_all() {
document.getElementById("user").innerHTML = " ";
form.txt_name.value=" ";
form.txt_name.focus();
}
</script>
</head>
<body>
<form name="form" method="post">
Enter your name
<input type="text" name="txt_name" size="15"><br><br>
<input type="button" onclick="user_name()" value="Ok">
<input type="button" onclick="clear_all()" value="Clear">
<br><br>
<div id="user"> </div>
</form>
</body>
</html>
No comments:
Post a Comment