problen with form validation not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LRW

    #1

    problen with form validation not working

    I'm trying to get the script to alert you of certain blank fields when
    you submit the form, but it just doesn't work, and I can't see why. By
    all appearances it should be working.
    But I get no errors, and then you SUBMIT it just goes right on to the
    next page completely bypassing the validation.
    What am I doing wrong? What am I missing?
    If someone could give me a clue, I'd appreciate it!

    Below is the JS and the relavent parts of the form.
    Thanks!!
    Liam

    <script language=JavaSc ript>
    <!-- Begin
    function ValidateE1() {
    var FieldList = "";
    if (document.f1.to email.value.len gth < 2 ){
    FieldList = "To Email\n";
    }
    if (document.f1.fr omemail.value == "") {
    FieldList = FieldList + "From Email\n";
    }
    if (document.f1.ms g.value == "") {
    FieldList = FieldList + "Message\n" ;
    }
    if (FieldList != "") {
    alert("We did not get all the information we need from you.\n\n
    Please fill in the following field(s):\n\n" + FieldList);
    return false;
    } else {
    document.f1.sub mit();
    }
    }
    // End -->
    </script>
    --SNIP--
    <form name="f1" id="f1" method="post" action="emailer proc.bkk"
    onSubmit="retur n ValidateE1();" >
    --SNIP--
    <td valign="top"><i nput name="toemail" id="toemail" type="text"
    size="40">
    <span class="labelBlu e"><br>^-- Recipient's E-mail
    address</span> </td>
    --SNIP--
  • Lee

    #2
    Re: problen with form validation not working

    LRW said:[color=blue]
    >
    >I'm trying to get the script to alert you of certain blank fields when
    >you submit the form, but it just doesn't work, and I can't see why. By
    >all appearances it should be working.
    >But I get no errors, and then you SUBMIT it just goes right on to the
    >next page completely bypassing the validation.
    >What am I doing wrong? What am I missing?
    >If someone could give me a clue, I'd appreciate it!
    >
    >Below is the JS and the relavent parts of the form.[/color]

    When posting code, please reformat it to use fewer columns.
    You can see what happens to your code when I include it in
    my reply:

    [color=blue]
    >
    ><script language=JavaSc ript>
    > <!-- Begin
    > function ValidateE1() {
    > var FieldList = "";
    > if (document.f1.to email.value.len gth < 2 ){
    > FieldList = "To Email\n";
    > }
    > if (document.f1.fr omemail.value == "") {
    > FieldList = FieldList + "From Email\n";
    > }
    > if (document.f1.ms g.value == "") {
    > FieldList = FieldList + "Message\n" ;
    > }
    > if (FieldList != "") {
    > alert("We did not get all the information we need from you.\n\n
    > Please fill in the following field(s):\n\n" + FieldList);
    > return false;
    > } else {
    > document.f1.sub mit();
    > }
    > }
    > // End -->
    > </script>[/color]


    I don't know what system you're using that didn't flag the
    error. Netscape 7 caught it right away.
    The problem is that the first line of your alert contains an
    unterminated string.
    You can't just continue string literals from line to line.

    Use something like:

    alert("We did not get all the information we need from you.\n\n" +
    "Please fill in the following field(s):\n\n" + FieldList);

    Comment

    • LRW

      #3
      Re: problen with form validation not working

      Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<c8e1n00kv d@drn.newsguy.c om>...
      [color=blue]
      > When posting code, please reformat it to use fewer columns.
      > You can see what happens to your code when I include it in
      > my reply:
      >
      > --SNIP--
      >
      > I don't know what system you're using that didn't flag the
      > error. Netscape 7 caught it right away.
      > The problem is that the first line of your alert contains an
      > unterminated string.
      > You can't just continue string literals from line to line.
      >[/color]

      I couldn't see what you were talking about "fewer columns" until I
      replied to your message. I'm using deja.com for my newsreader, and the
      display shows nice and fine until I go into edit mode and it shows all
      the extra columns. Sorry.

      I was using Editplus (an elaborite notepad basically) to write with
      and Avant browser (a glorified Internet Explorer) to view with. I'm
      chagrined that Netscape told you what the problem was but neither
      Avant nor IE told me.
      What I did was go back through and deleted all blank spaces and
      carriage returns and respaced and carriaged returned where necessary,
      and that did it. What I found weird, is in several places when I'd
      "delete" nothing would change and I'd have to delete once or twice
      before the next character would move. Sort of like there were
      invisible characters...li ke unintentional carriage returns perhaps.

      But, it works great now! Thanks for the help!!
      Liam

      Comment

      Working...