Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:13:23+00:00 2026-06-12T10:13:23+00:00

Hey guys working on some form validation on our jsp page. I have alert

  • 0

Hey guys working on some form validation on our jsp page.

I have alert boxes coming up when you enter no value or a non numeric value in the capacity field. But after clicking “OK” the page is redirected to an error:

HTTP Status 500 - For input string: ""

OR when entering “a” in the capacity field

HTTP Status 500 - For input string: "a"

How would I reload the page instead of taking me to the error page?

I have already tried many in built Javascript functions but still directed to the error page, like location.reload() etc.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Mars University Lab System</title>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen">
</head>

<body>
<jsp:include page="headerLecturer.jsp"/>
<script>

function chkNumeric(strString)
                   //  check for valid numeric strings  
                   {
                       var strValidChars = "0123456789.-";
                       var strChar;
                       var blnResult = true;

                       if (strString.length == 0) return false;

                       //  test strString consists of valid characters listed above
                       for (i = 0; i < strString.length && blnResult == true; i++)
                          {
                                strChar = strString.charAt(i);
                                if (strValidChars.indexOf(strChar) == -1)
                             {
                             blnResult = false;
                             }
                          }
                       return blnResult;
                   }


                 function validateForm()
                 {
                    var capacity=document.forms["createLabs"]["capacity"].value;
                    var day=document.forms["createLabs"]["day"].value;
                    var time=document.forms["createLabs"]["time"].value;
                    var room=document.forms["createLabs"]["room"].value;

                    if (capacity==null || capacity=="")
                      {
                            alert("Capacity must be filled out");
                            document.createLabs.capacity.focus();
                            return false;
                      }
                    else if(day==null || day=="")
                     {
                            alert("Day must be filled out");
                            document.createLabs.day.focus();
                            return false;
                     }
                     else if(time==null || time=="")
                     {
                            alert("Time must be filled out");
                            document.createLabs.time.focus();
                            return false;
                     }
                     else if(room==null || room=="")
                     {
                            alert("Room must be filled out");
                            document.createLabs.room.focus();
                            return false;

                    }
                    else if (chkNumeric(document.createLabs.capacity.value) == false) 
                    {
                            alert("Please check - non numeric value!");
                            document.createLabs.room.focus();
                            return false;

                    }
                    else if (chkNumeric(document.createLabs.room.value) == false) 
                    {
                            alert("Please check - non numeric value!");
                            document.createLabs.room.focus();
                            return false;
                    }




                            var link2 = document.getElementById('submit');

                                link2.onclick = function ()     
                                {
                                    if( confirm("Please fill in all the required fields") )
                                    {
                                        window.location.reload();
                                    }
                                    return false;
                                }


}


</script>

<tr>
<td>
</td>
</tr>

<tr>
<td>
<div id = "centrecontent">
<br>
<h3>Create Labs</h3>
<%String[] list1 = (String[])request.getAttribute("res1"); %>
<%String[] list2 = (String[])request.getAttribute("res2"); %>


        <form name ="createLabs" ACTION="CreateLab" method="post">

        Subject: <select name="subject_id">
        <%
        for(int i=0; i<list1.length; i++)  
        {
            //for(int m=0; m<list2.length;i++)
            //{
                out.println("<option value="+list1[i]+"> "+list2[i]+" </option>");

        //}
            out.println("list1:"+list1[0]);
            }
            %>
        </select><br><br>
        Capacity: <input type="text" name="capacity"/><br /><br>
        <input type="hidden" name="spots_left"/>
        Day: <input type="text" name="day"/><br /><br>
        Time (HH:MM:SS): <input type="time" name="time"/><br /><br>
        Room: <input type="text" name="room"/><br /><br>
        <input type=SUBMIT value="Submit" name="Submit" onClick="validateForm()" />

    </form>
</div>

<jsp:include page="footer.jsp"/>


</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:13:25+00:00Added an answer on June 12, 2026 at 10:13 am

    The problem is comming from the server side, so the problem is with the validation
    in javascript functions

    I changed validateForm but did not check.

    Maybe it will help

          function validateForm()
             {
                var capacity=document.forms["createLabs"]["capacity"].value;
                var day=document.forms["createLabs"]["day"].value;
                var time=document.forms["createLabs"]["time"].value;
                var room=document.forms["createLabs"]["room"].value;
    
                if (capacity === undefined)
                  {
                        alert("Capacity must be filled out");
                        document.createLabs.capacity.focus();
                        return false;
                  }
    
                    if(day === undefined)
                 {
                        alert("Day must be filled out");
                        document.createLabs.day.focus();
                        return false;
                 }
    
                     if(time === undefined)
    
                 {
                        alert("Time must be filled out");
                        document.createLabs.time.focus();
                        return false;
                 }
    
                     if(room === undefined)
    
                 {
                        alert("Room must be filled out");
                        document.createLabs.room.focus();
                        return false;
    
                }
    
                    if ( isNaN(capacity))
                    {
                         alert("Please check - non numeric value!");
                        document.createLabs.room.focus();
                        return false;
                    }
    
                        if ( isNaN(room))
                    {
                         alert("Please check - non numeric value!");
                        document.createLabs.room.focus();
                        return false;
                    }
    
                    if(room === undefined)
                {
                        alert("Please check - non numeric value!");
                        document.createLabs.room.focus();
                        return false;
                }
    
    
    
    
                        var link2 = document.getElementById('submit');
    
                            link2.onclick = function ()     
                            {
                                if( confirm("Please fill in all the required fields") )
                                {
                                    window.location.reload();
                                }
                                return false;
                            }
    
    
                                }
    

    In addition you need to put validateForm trigger for “onsubmit” event

    <form name ="createLabs" ACTION="CreateLab" method="post" onsubmit="return validateForm()">
    
            Subject: <select name="subject_id">
            <%
            for(int i=0; i<list1.length; i++)  
            {
                //for(int m=0; m<list2.length;i++)
                //{
                    out.println("<option value="+list1[i]+"> "+list2[i]+" </option>");
    
            //}
                out.println("list1:"+list1[0]);
                }
                %>
            </select><br><br>
            Capacity: <input type="text" name="capacity"/><br /><br>
            <input type="hidden" name="spots_left"/>
            Day: <input type="text" name="day"/><br /><br>
            Time (HH:MM:SS): <input type="time" name="time"/><br /><br>
            Room: <input type="text" name="room"/><br /><br>
            <input type="submit" value="Submit" name="Submit"   />
    
        </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, working on an event calendar. I'm having some trouble getting my column
hey guys, i have downloaded mondor's captcha control, and implemented on localhost, thats working
Hey guys... I'm working on creating one of my first websites and currently have
Hey guys, I have a raidan style 2d flying/fighter game that im working on.
Hey guys I have the following code working which is sending a GET Request
Hey guys I have my script here that is supposed to do some stuff
hey guys im working on a task to make my story's links like this
Hey guys, I'm working on a status-Updater. It works, there is just one problem,
Hey guys, I was working on a simple chat program to brush up on
Hey guys this is a bit of a homework puzzle I'm working on and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.