user3868051
user3868051

Reputation: 1249

Form validation error validation not processing

The following is my script :

<head>
<script type="text/javascript">
function del_form()
{
    var s_id=document.Delete.s_id;
    if(s_id.value != "")
    {
    //window.alert("Please enter the ID!");
    alert("Please enter the ID!");
    return false;
   }
 return true;
}
</script>

This the the form :

<body>
  <form name="Delete" method="post" onsubmit=" return del_form()"     action="AdminDeleteShop2.jsp" >
Enter the ID of the Shop which is to be deleted : <input type="text" name ="s_id"     id="s_id">
<input type="submit" value="Delete!"><br>
</form><br><br>
<form name="Back" method="post" action="MasterMenu.jsp">
<input type="submit" value="Back">
</form><br><br>
</body>

The problem is that without performing form validation it is going onto the next page that is AdminDeleteShop2.jsp. And there it is giving me the following error :

org.apache.jasper.JasperException: An exception occurred processing JSP page /AdminDeleteShop2.jsp at line 26 : int s_id = Integer.parseInt(s_id_string);
root cause : java.lang.NumberFormatException: For input string: ""

Connection con = DriverManager.getConnection( host, uName, uPass );
 Scanner sc = new Scanner(System.in);
 String s_id_string = (String)request.getParameter("s_id");
 int s_id = Integer.parseInt(s_id_string);
 Statement stmt2 = con.createStatement();
 int check = stmt2.executeUpdate("delete from ShopSystem.Shop where s_id="+s_id+"");
 if(check>0)
 %> S_ID = <%= s_id %> has been deleted successfully.<br>   <%  
}
else
{   %>  Sorry the action cannot be completed. Please check if valid S_ID was     entered<br>                <%         
}
sc.close();
%>
<form name="Back" method="post" action="MasterMenu.jsp">
<input type="submit" value="Back">
</form><br><br>

Upvotes: 0

Views: 47

Answers (1)

Arjun Prajapati
Arjun Prajapati

Reputation: 273

kindly change your condition in script as below

function del_form(){

var s_id=document.Delete.s_id;

if(s_id.value == "")

{

 //window.alert("Please enter the ID!");

    alert("Please enter the ID!");

    return false;

   }

 return true;

}

Upvotes: 1

Related Questions