I have created a home page with a division in which 2 other JSP pages are to load. The validations fire properly when I lauch those 2 pages seperately. The problem is, validations arent working when they load within the first page. How can I solve this? Should i write the script within the first page?
Home Page Code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
var zx;
function a()
{
zx="Login.jsp";
c(zx)
}
function b()
{
zx="Register.jsp";
c(zx)
}
function c(zx)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("a").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",zx,true);
xmlhttp.send();
}
</script>
<link rel="stylesheet" type="text/css" href="projstyle.css" />
</head>
<body>
<form method="post" action="/NewServlet">
<font color="white">
<br>
<div id="a"><<input value="Login" type="button" name="btn1" onclick="a();">
<input value="Register" name="btn2" type="button" onclick="b();">
</div>
</font>
</form>
</body>
</html>
two other forms :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function a()
{
var x = document.forms.frm1.UserID.value;
var y = document.forms.frm1.Pass.value;
if(x=="" || y=="")
{
alert("Required Field cannot be left Blank");
if(x!="")
{
document.forms.frm1.Pass.focus();
return false;
}
else
{
document.forms.frm1.UserID.focus();
return false;
}
}
}
</script>
</head>
<body>
<form method="post" action="/Login" onsubmit="return a()" name="frm1">
Login : <input name="UserID" type="text"/>
<br>
Password : <input name="Pass" type="password" maxlength="18"/>
<br>
<input name="btn1" type="submit" value="Login!" />
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script language="javascript" type="text/javascript">
function a(){
var x = document.forms.frm1.Pass1.value;
var y = document.forms.frm1.Pass2.value;
var u = document.forms.frm1.txt1.value;
var i = document.forms.frm1.txt2.value;
var o = document.forms.frm1.sel1.value;
if(x==null || x=="" || u==null || u=="" || i==null || i == "" || o=="Select One")
{
alert("Fields cannot be left blank");
return false;
}
if(x!=y)
{
alert("The Passwords do NOT match.");
return false;
}
}
</script>
</head>
<body><font color="white">
<form name="frm1" method="post" action="/Register" onsubmit="return a()"><table>
<tr><td align="right">Name :</td><td><input name="txt1" type="text" /></td></tr>
<br>
<tr><td align="right">UserID :</td><td><input name="txt2" type="text" /></td></tr>
<br>
<tr><td align="right">Password :</td><td><input name="Pass1" type="password" /></td></tr>
<br>
<tr><td align="right">Confirm Password :</td><td><input name="Pass2" type="password" /></td></tr>
<br>
<tr><td align="right">City :</td><td><select name="sel1">
<option value="Select One">Select One</option>
<option value="Hyderabad">Hyderabad</option>
<option value="Pune">Pune</option>
<option value="Bangalore">Bangalore</option>
</select>
</td>
<tr>
<br>
<tr><td align="right"><input value="Register" type="submit" /><td><td><input value="Cancel" type="submit" ></td></tr></table>
</form></font>
</body>
</html>