Unable to Access Javascript File in JSP Page under <script> tag

Viewed 27

In this code, I am trying to use javascript within the JSP page itself but it is not taking any javascript keyword. Basically, JavaScript is not working on this JSP page. Can anyone please let me know what the issue is?

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>  
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
   
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home Page</title>
<script type="text/javascript">

function validateUserName(){
    var userName =document.getElementById('yn').value;
    if(userName.length<2){
        alert("Your name should have atleast one charactor");
        return false;
        }
    else{
        return true;
        }
}
</script>

</head>
<body>
<h1 align="center">Love Calculator</h1>

<hr/>
<form:form action="process-homepage" method="get" modelAttribute="userinfo" onsubmit="return validateUserName()">
<div align="center">
<p>
<label for="un">Your Name:</label>
<form:input  id="un" path="yourName"></form:input>
</p>
<p>
<label for="cn">Crush's Name:</label>
<form:input id="cn" path="crushName"></form:input>
</p>
<input type="submit" value="Calculate"></input>
</div>
</form:form>
</body>
</html>
0 Answers
Related