View Full Version : Alert box problem

06-10-2004, 08:11 PM
if you leave all the boxes empty it will alert you one after the other without giving you the oppurtunity of filling out the empty box. How can i alert the user of an empty box one at a time?.

function validation(form) {

var person = form.person.value
var place = form.place.value
var descriptive = form.descriptive.value
var thing = form.thing.value
var status = form.status.value
var action = form.action.value
var persontwo = form.person2.value
var thingtwo = form.thing2.value
var emotion = form.emotion.value
var statement = form.statement.value

if ((person==null)||(person=="")){ // if variable "name"s' value = nothing
alert ('Enter a character name');
form.person.focus(); // return curser to "name" field
//return false;
if ((place==null)||(place=="")){ // if "email" field = nothing or does not include "@" and "."
alert ('Enter a place'); // alert "message"
//return false;
if ((descriptive==null)||(descriptive=="")){ // if variable "postcode" = nothing or no number
alert ('Enter a feeling');
//return false;
if ((thing==null)||(thing=="")){
alert ('Enter a thing');
//return false;
if ((status==null)||(status=="")){
alert ('Enter a frame of mind!');
//return false;
if ((action==null)||(action=="")){
alert ('Enter an action!');
//return false;
if ((persontwo==null)||(persontwo=="")){ // if variable "name"s' value = nothing
alert ('Enter a second character');
form.person2.focus(); // return curser to "name" field
//return false;
if ((thingtwo==null)||(thingtwo=="")){
alert ('Enter a second thing!');
//return false;
if ((emotion==null)||(emotion=="")){
alert ('Enter an emotion');
//return false;
if ((statement==null)||(statement=="")){
alert ('Enter a statement');
//return false;

setCookie("person", form.person.value, now);
setCookie("place", form.place.value, now);
setCookie("descriptive", form.descriptive.value, now);
setCookie("thing", form.thing.value, now);
setCookie("status", form.status.value, now);
setCookie("action", form.action.value, now);
setCookie("person2", form.person2.value, now);
setCookie("thing2", form.thing2.value, now);
setCookie("emotion", form.emotion.value, now);
setCookie("statement", form.statement.value, now);
//return (form.person,form.place,form.descriptive,form.thing,form.status,form.action,form.person2,form.thing2 ,form.emotion,form.statement);} // the "MakeWin" function is executed at the end of this (validate) function

06-10-2004, 10:11 PM
uncomment out the return parts, then in your form have something like

onsubmit="return validation()"


<form name="foo" action="foo.ext" onSubmit="return validation(this)">

then once the returns are uncommented, it will check the first field, and if blank, return false and not check any more.

if ((person==null)||(person=="")){ // if variable "name"s' value = nothing
alert ('Enter a character name');
form.person.focus(); // return curser to "name" field
return false;

hope that helps.

06-11-2004, 06:04 AM
Don't check for null values as user inputs will never be null.