
i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation works correctly but when my validation fails i am getting an alert window and i am reverting to next page. The thing is i want to stay in same page if validation fails. Do this favor for me. Thanks s advance
sports1.jsp file:-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<HTML>
<head>
<SCRIPT language="javascript">
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
function validate()
{
var chks = document.getElementsByName('checkk');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select atleast one Asset.");
return false;
}
return true;
}
function validate1()
{
if (document.myform.status.value=="0")
{
alert("Please Select Status");
return false;
}
return true;
}
function validate2()
{
validate1();
validate();
}
</script>
</head>
<body>
<FORM name="myform" method="POST" ACTION="sports.jsp" onsubmit="return validate2(this)">
<center>
<br>Select your AssetCode: </br>
<table>
<tr>
<td>
<input TYPE=checkbox name=checkk id="agree" VALUE=As10>
</td>
<td>
As10
</td>
<td><select name="status">
<option value="0">Select</option>
<option value="Activate">Activate</option>
<option value="Deactivate">Deactivate</option>
<option value="scrap">Scrap</option>
</select>
</td>
<td><INPUT TYPE=submit name=Convert Value="Convert" ></td>
</tr>
<tr>
<td>
<input TYPE=checkbox name=checkk id="agree" VALUE=As11>
</td>
<td>
As11
</td>
</tr>
<tr>
<td>
<input TYPE=checkbox name=checkk id="agree" VALUE=As12>
</td>
<td>
As12
</td>
</tr>
<tr>
<td>
<input TYPE=checkbox name=checkk id="agree" VALUE=As13>
</td>
<td>
As13
</td>
</tr>
<tr>
<td>
<input TYPE=checkbox name=checkk id="agree" VALUE=As14>
</td>
<td>
As14
</td>
</tr>
<tr>
<td>
<input type="button" name="SelectAll" value="SelectAll" onClick="checkAll(document.myform.checkk)">
</td>
</tr>
<tr>
<td>
<input type="button" name="UnSelectAll" value="UnSelectAll" onClick="uncheckAll(document.myform.checkk)">
</td>
</tr>
</table>
<br>
</center>
</FORM>
</BODY>
</HTML>
sports.jsp file:-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%! String[] asset; %>
<center><b>You have selected:</b>
<%
asset = request.getParameterValues("checkk");
if (asset != null)
{
for (int i = 0; i < asset.length; i++)
{
out.println ("<b>"+asset[i]+"<b>");
}
}
else out.println ("<b>None<b>");
%>
</br>
<%
String selectedValue=request.getParameter("status");
out.println("Selected Status is: "+selectedValue);
%>
</center>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.