Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript and JSP not reloading
    primarykey
    data
    text
    <p>Hey guys working on some form validation on our jsp page.</p> <p>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: </p> <pre><code>HTTP Status 500 - For input string: "" </code></pre> <p>OR when entering "a" in the capacity field</p> <pre><code>HTTP Status 500 - For input string: "a" </code></pre> <p>How would I reload the page instead of taking me to the error page?</p> <p>I have already tried many in built Javascript functions but still directed to the error page, like location.reload() etc. </p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Mars University Lab System&lt;/title&gt; &lt;link rel="stylesheet" href="style.css" type="text/css" media="screen"&gt; &lt;/head&gt; &lt;body&gt; &lt;jsp:include page="headerLecturer.jsp"/&gt; &lt;script&gt; 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 &lt; strString.length &amp;&amp; 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; } } &lt;/script&gt; &lt;tr&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div id = "centrecontent"&gt; &lt;br&gt; &lt;h3&gt;Create Labs&lt;/h3&gt; &lt;%String[] list1 = (String[])request.getAttribute("res1"); %&gt; &lt;%String[] list2 = (String[])request.getAttribute("res2"); %&gt; &lt;form name ="createLabs" ACTION="CreateLab" method="post"&gt; Subject: &lt;select name="subject_id"&gt; &lt;% for(int i=0; i&lt;list1.length; i++) { //for(int m=0; m&lt;list2.length;i++) //{ out.println("&lt;option value="+list1[i]+"&gt; "+list2[i]+" &lt;/option&gt;"); //} out.println("list1:"+list1[0]); } %&gt; &lt;/select&gt;&lt;br&gt;&lt;br&gt; Capacity: &lt;input type="text" name="capacity"/&gt;&lt;br /&gt;&lt;br&gt; &lt;input type="hidden" name="spots_left"/&gt; Day: &lt;input type="text" name="day"/&gt;&lt;br /&gt;&lt;br&gt; Time (HH:MM:SS): &lt;input type="time" name="time"/&gt;&lt;br /&gt;&lt;br&gt; Room: &lt;input type="text" name="room"/&gt;&lt;br /&gt;&lt;br&gt; &lt;input type=SUBMIT value="Submit" name="Submit" onClick="validateForm()" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;jsp:include page="footer.jsp"/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload