#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0

    Question javaScript form checker


    Hi there,

    I have tried to write a simple JavaScript form checker to see that none of the fields are empty and that the password is consistent (the password has to be entered twice).

    <script language="JavaScript">
    <!-- Hide the script content
    function form_checker()
    {
    var numOfElements = form.elements.length;
    var submitForm = true;
    for (var i=0; i<numOfElements; i++)
    {
    if ((form.elements[i].value == null) (form.elements[i].value = ""))
    {
    if (form.elements[i].name != "submit")
    alert ("Please fill in the following fields: " + form.element[i].name);
    submitForm = false;
    break;
    }
    if(password1 != password)
    {
    alert ("Your password is inconsistent. Please check and retype.")
    submitForm = false;
    break;
    }
    }
    if(submitForm)
    form.submit();
    }
    // End hiding -->
    </script>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0

    form checker cont.


    forgot to say that it isn't working.
  4. #3
  5. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Please read this thread on how to post a question. &#187; http://forums.devshed.com/t24097/s.html &#171;

    "isn't working" doesn't tell us anything. Obviously it isn't working or you wouldn't have posted?

    What _exactly_ do you expect it to do? (you've sorta answered that) What errors are you getting if any? And please give us the code for the form b/c I don't want to have to make one to match your script.

    Also, please learn to use the &#91;code] <html> goes here &#91;/code] VB tags, it helps us quite a bit when checking your code.

IMN logo majestic logo threadwatch logo seochat tools logo