error checking on form

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

    error checking on form

    hey peoples.

    I have a simple form (currently two fields) which is then passed to an ASP
    page thats stores the data in a dbase

    I have an error checking script which I can't get to work. the script is :


    <script language="JavaS cript">

    <!-- Hide from older browsers...

    //Function to check form is filled in correctly before submitting
    function CheckForm () {

    //Intialise variables
    var errorMsg = "";
    var errorMsgLong = "";

    //Check for a name
    if (document.frmre gnewuser.name.v alue == ""){
    errorMsg += "\n\tName \t\t- Enter your Name";
    }



    //Check for comments
    if (document.frmre gnewuser.e-mail.value == ""){
    errorMsg += "\n\tCommen ts \t- Enter a valid email address";
    }


    //If there is aproblem with the form then display an error

    if ((errorMsg != "") || (errorMsgLong != "")){
    msg =
    "______________ _______________ _______________ _______________ ________\n\n";
    msg += "Your registration could not be completed because there are
    problem(s) with the form.\n";
    msg += "Please correct the problem(s) and re-submit the form.\n";
    msg +=
    "______________ _______________ _______________ _______________ ________\n\n";
    msg += "The following field(s) need to be corrected: -\n";

    errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
    return false;
    }

    return true;
    }

    // -->
    </script>


    I have the submit button and the following code in the form

    onsubmit = "return checkform ();"

    but it doesn't run the check...can anyone see anything obvious??

    many thanks



  • Janwillem Borleffs

    #2
    Re: error checking on form

    Alistair wrote:[color=blue]
    > errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);[/color]

    This should be just:
    alert(msg + errorMsg + "\n" + errorMsgLong);


    JW



    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: error checking on form

      "Alistair" <news@*remove*a listairb.co.uk> writes:
      [color=blue]
      > I have an error checking script which I can't get to work. the script is :[/color]

      A description of how it fails, best in compairison to what it should do,
      would make it a *lot* easier to check.
      [color=blue]
      > <script language="JavaS cript">[/color]

      In HTML 4, the type attribute is *required*. Use
      <script type="text/javascript">
      It works in all browsers and is also correct.
      [color=blue]
      > <!-- Hide from older browsers...[/color]

      Not necessary.
      [color=blue]
      > if (document.frmre gnewuser.e-mail.value == ""){[/color]

      "e-mail" is not a valid identifier. This gives the error that "mail"
      is an undefined variable. Write it as:
      if (document.forms['frmrengewuser'].elements['e-mail'].value == ""){

      [color=blue]
      > errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);[/color]

      As Janwillem Borleffs said, the "errorMsg +=" shouldn't be there.
      [color=blue]
      > but it doesn't run the check...can anyone see anything obvious??[/color]

      You should enable the showing of script errors when you program.
      I assueme you use IE, since you don't say anything.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...