JavaScript Tutorial:-
In this tutorial, we will describe how to write javascript on the JSP Web page using JavaScript.
In this tutorial, we will describe how to write javascript on the JSP Web page using JavaScript.
Create a JSP Web Page and design forms.
jsdemo1.jsp:-
<%--
Document: jsdemo1
Created on : Jan 28, 2020, 3:42:31 AM
Author: Hp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
alert("welcome in JS");
</script>
<script src="javascriptfile.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<button onclick="fun()">Click</button>
</body>
</html>
<%--
Document: jsdemo1
Created on : Jan 28, 2020, 3:42:31 AM
Author: Hp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
alert("welcome in JS");
</script>
<script src="javascriptfile.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<button onclick="fun()">Click</button>
</body>
</html>
Create javascript.js:-
function fun()
{
alert("hello");
}
Code of another JSP Page using Javascript to Calculate Simple Interest?
<html>
<head>
<script>
function calc()
{
p = document.getElementById("txtp").value;
r = document.getElementById("txtr").value;
t = document.getElementById("txtt").value;
si = (parseInt(p)*parseFloat(r)*parseInt(t))/100;
document.getElementById("res").innerHTML=si;
// alert('result is '+si);
}
</script>
</head>
<body>
<input type="text" id="txtp" placeholder="enter p" /><br><br>
<input type="text" id="txtr" placeholder="enter r" /><br><br>
<input type="text" id="txtt" placeholder="enter t" /><br><br>
<input type="button" value="click" onclick="calc()" />
<br><br>
<div id="res"></div>
</body>
</html>
POST Answer of Questions and ASK to Doubt