form validation using JSP and JavaScript

bublathejuggla used Ask the Experts™
hi. i have a registration page contructed using HTML where users can enter their personal details to register with my system. I have used javaScript to validate the inputs by i.e. checking no fields have been left blank. On submission, if the user selects the same userid as an existing user, they are directed to an error page stating the error and they can follow a link back to the registration page to make an alternative choice. HOWEVER, javascript.history.back(), which is what im using, retains all previous inputs on returning to the registration page. This includes the previous userid the user entered so they are again taken to the error page. This event loops and is inevitable! does anyone please know a way around this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hello bublathejuggla,

You can use the onLoad event of the BODY tag of the first page to clear the input.

Hope this helps



unfortunately, it would be asking too much of users to re-enter all of their data again when only their userid needs to be changed. although this solution works, a better one would be more convenient and appropriate
You don't need to clear all the input fields. Just the ones you want to:

function cleanup(){
<BODY onLoad="cleanup">

(sorry for any Javascript errors. my JS is a bit rusty since I haven't used it lately)
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.


You forget to put a parentheses in the OnLoad event function
should be like this"

 <BODY OnLoad="cleanup()">
oops... so I did.
Thanks for the comment.
  The following works

<SCRIPT LANGUAGE = "JavaScript" type = "text/javascript">
function cleanup(){
document.form1.EMAILADD.value = "";
document.form1.PASSWORD1.value = "";
document.form1.PASSWORD2.value = "";

<BODY BGCOLOR = "#7FFFD4" onLoad="cleanup()">

<form name="form1">
   <p><input type="text" name="EMAILADD" size="20"></p>
  <p><input type="text" name="PASSWORD1" size="20"></p>
  <p><input type="text" name="PASSWORD2" size="20">
  <input type="reset" value="Reset" name="B2"></p>


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial