Screen refreshes after displaying error message

Saturday, September 20, 2014


I'm creating a registration page that, among other things, displays an error message when an invalid date is entered. The JavaScript I wrote detects the error and displays the error message -- for less than one (1) second -- then the entire page refreshes to display a blank registration page. Why does it do that and how can I get it to stop refreshing?

JavaScript Code:
function setText(elementId, message)
'use strict';
if ((typeof elementId == 'string') && (typeof message == 'string'))
var output = document.getElementById(elementId);
if (output.textContent !== undefined)
.textContent = message;
else // using IE
.innerText = message;

function process()
'use strict';
var dob;     // retrieve dob value from HTML
var msg;     // output error message
var dobDate; // convert dob to date type
= document.getElementById('dob');
= '';
if (dob && dob.value)
= new Date(dob.value);
if (dobDate.getTime())
else // invalid date or invalid input
= 'Invalid date!';
('errMsg', msg);
} // end if
}  // end process()

function init()
'use strict';
.getElementById('frmReg').onsubmit = process;

.onload = init;

Web Code:
<!doctype html>
<meta charset="utf-8" />
<title>Registration Page</title>
<!--[if lt IE 9]>
    <script src=""></script>

<link rel="stylesheet" href="css/mainstyle.css" />
<!-- registration page -->
<h1>Register Your Child</h1>
<p>This page allows you to enter your child's information in relation to the Two Hands preschool. </p>
<form action="" id="frmReg" novalidate>
<legend class="fsheader">Identification</legend>
<p>Enter name and date of birth of the child that will be enrolling in the upcoming year. </p>
<label for="firstName">First Name: </label><input type="text" name="firstName" id="firstName" required />
<label for="lastName">Last Name: </label><input type="text" name="lastName" id="lastName" required />
<label for="dob">Birth Date: </label><input type="text" name="dob" id="dob" placeholder="mm/dd/yyyy" required />&nbsp;&nbsp;<span id="errMsg"></span>
<legend class="fsheader">Placement</legend>
<h2><label for="daysAttend">Days Attending: </label></h2>
<p>Which days will the child be attending preschool? </p>
<input type="checkbox" name="monday" id="monday" value="monday" />Monday <br />
<input type="checkbox" name="tuesday" id="tuesday" value="tuesday" />Tuesday <br />
<input type="checkbox" name="wednesday" id="wednesday" value="wednesday" />Wednesday <br />
<input type="checkbox" name="thursday" id="thursday" value="thursday" />Thursday <br />
<input type="checkbox" name="friday" id="friday" value="friday" />Friday <br />
<h2><label for="sched">Schedule Type: </label></h2>
<p>Which portion of the day will the child be attending? </p>
<select name="sched" id="sched">
<option value="Morning">Morning</option>
<option value="Afternoon">Afternoon</option>
<option value="FullDay">Both Morning and Afternoon</option>
<p />
<label for="register"></label><input type="submit" value="Register" id="submit" />
<script src="js/reg.js"></script>


Patrick Wong
Newbie Web Developer

"On a clear disk, you can seek forever..."

You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit


Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii