通過了關於SO的其他類似問題,但無法解決我的問題。我已經在script
標記內寫入了src
路徑。如何鏈接jsp中的外部js文件
下面是程序:
function validate()
{
var fname = document.myForm.fname.value;
var lname = document.myForm.lname.value;
if(fname=="" && lname=="")
{
alert("First and last name cannot be emtpy");
return false;
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="/js/validation.js"></script>
<title>Registration Form</title>
</head>
<body>
<form name="myForm" action="RegistrationServlet.do" method="POST" onsubmit="return validate()">
First name:<input type="text" name="fname" /> <br/>
Last name:<input type="text" name="lname" /><br/>
Gender: Male<input type="radio" name="male" /> Female<input type="radio" name="male" /><br/>
Mobile:<input type="tel" name="mobile" /><br/>
Email:<input type="email" name="email" /><br/>
Address:<textarea name="tarea"></textarea><br/>
Street:<input type="text" name="street" /><br/>
Area:<input type="text" name="area" /><br/>
City:<select>
<option value="hyderabad">hyderabad</option>
<option value="secunderabad">secunderabad</option>
<option value="delhi">delhi</option>
<option value="mumbai">mumbai</option>
</select>
State: <input type="text" name="state" /><br/>
Country: <input type="text" name="country" /><br/>
Pin: <input type="text" name="pin" /><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
我的js文件的文件夾中稱爲webapp目錄內的js
它在這裏工作過的片段,但它不是我的瀏覽器(Chrome)工作。它只是將請求轉發到servlet而無需驗證 – kittu