Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Alert box problem

    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"
    form.place.focus();
    //return false;
    }
    if ((descriptive==null)||(descriptive=="")){ // if variable "postcode" = nothing or no number
    alert ('Enter a feeling');
    form.descriptive.focus();
    //return false;
    }
    if ((thing==null)||(thing=="")){
    alert ('Enter a thing');
    form.thing.focus();
    //return false;
    }
    if ((status==null)||(status=="")){
    alert ('Enter a frame of mind!');
    form.status.focus();
    //return false;
    }
    if ((action==null)||(action=="")){
    alert ('Enter an action!');
    form.action.focus();
    //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!');
    form.thing2.focus();
    //return false;
    }
    if ((emotion==null)||(emotion=="")){
    alert ('Enter an emotion');
    form.emotion.focus();
    //return false;
    }
    if ((statement==null)||(statement=="")){
    alert ('Enter a statement');
    form.statement.focus();
    //return false;
    }

    else{
    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
    }
    //-->

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    uncomment out the return parts, then in your form have something like

    onsubmit="return validation()"

    eg:

    Code:
    <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.

    Code:
    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.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Don't check for null values as user inputs will never be null.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •