Form submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nerry
    New Member
    • Sep 2006
    • 14

    #1

    Form submit button

    Hello, i'm new to HTML

    I've created a registration form and have a submit button. i want that if the form is blank and submit is clicked that I could link it to a page saying, "please input information on form" or "don't leave form blank". As it now is, a page comes up saying "page cannot be displayed". this does not explain to the user what they did wrong.

    Once there is information on the form when the submit button is clicked, it is linked to a confirmation page....this works fine.

    Are there any suggestions as to how i can do this?? thanks so much!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Nerry
    Hello, i'm new to HTML

    I've created a registration form and have a submit button. i want that if the form is blank and submit is clicked that I could link it to a page saying, "please input information on form" or "don't leave form blank". As it now is, a page comes up saying "page cannot be displayed". this does not explain to the user what they did wrong.

    Once there is information on the form when the submit button is clicked, it is linked to a confirmation page....this works fine.

    Are there any suggestions as to how i can do this?? thanks so much!
    You validate the form using javascipt. A simple function to validate whether or not a textbox is empty is

    Code:
    function isEmpty(textbox) {
          if(textbox.value == "") {
    	return true;
          }
           else {
              return false;
          }
    }
    To use it just call it with the name of the box
    eg
    Code:
    function validateClients(form) {
            if(isEmpty(form.name)) {
    	alert("Client creation cannot proceed without name");
    	form.name.focus();
    	return false;
           }
    }
    on your form tag just do something like
    Code:
    <FORM name="myForm" onSubmit = "return validateClientClient(this)">

    Comment

    • Nerry
      New Member
      • Sep 2006
      • 14

      #3
      Originally posted by r035198x
      You validate the form using javascipt. A simple function to validate whether or not a textbox is empty is

      Code:
      function isEmpty(textbox) {
            if(textbox.value == "") {
      	return true;
            }
             else {
                return false;
            }
      }
      To use it just call it with the name of the box
      eg
      Code:
      function validateClients(form) {
              if(isEmpty(form.name)) {
      	alert("Client creation cannot proceed without name");
      	form.name.focus();
      	return false;
             }
      }
      on your form tag just do something like
      Code:
      <FORM name="myForm" onSubmit = "return validateClientClient(this)">

      Thx r035198x, but i'm still confused, with the code you gave, here's what i did:

      <script language="JavaS cript" type="text/JavaScript">

      function validateClients (form1) {
      if(isEmpty(form 1.CName)) {
      alert("Enter your company's name");
      form1.CName.foc us();
      return false;
      }
      }
      //-->
      </script>

      Here, form1 – name of the form, CName – is the name of a textbox value in the form, I’m not sure if I wrote the code properly. Where you placed Clients in validateClients , I know it was just an eg. But what does it refer to? Also is there a return true, that’s supposed to be in there somewhere?

      I put this script just above the form tag. I was unsure of where to put the script, because there is another script at the top in the <head> of the page.

      For the form tag you wrote onSubmit = "return validateClientC lient(this)", what does the (this) refer to and is Client supposed to be put twice?

      Thx again

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Nerry
        Thx r035198x, but i'm still confused, with the code you gave, here's what i did:

        <script language="JavaS cript" type="text/JavaScript">

        function validateClients (form1) {
        if(isEmpty(form 1.CName)) {
        alert("Enter your company's name");
        form1.CName.foc us();
        return false;
        }
        }
        //-->
        </script>

        Here, form1 – name of the form, CName – is the name of a textbox value in the form, I’m not sure if I wrote the code properly. Where you placed Clients in validateClients , I know it was just an eg. But what does it refer to? Also is there a return true, that’s supposed to be in there somewhere?

        I put this script just above the form tag. I was unsure of where to put the script, because there is another script at the top in the <head> of the page.

        For the form tag you wrote onSubmit = "return validateClientC lient(this)", what does the (this) refer to and is Client supposed to be put twice?

        Thx again

        First you can place the functions where you have the other javascripts preferrably in their own script tag as you've already done.
        Yes there should be a return true somewhere
        Code:
        function validateClients(form1) {
                if(isEmpty(form1.CName)) {
        	alert("Enter your company's name");
        	form1.CName.focus();
        	return false;
               }
               return true; // right here
        }
        for the form tag I made a typing error. You are supposed to call the javascript function validateClients and therefore the name of the function has to match.

        Since you put this in a form tag, when you say this, you are referring to this form. You are passing this form as a parameter to the function.

        Note this can also refer to the document so that you could also have said this.form1 meaning this documents's form1

        When used alone as just this however, it refers to the form.

        Accept my apologies for the errors. I've had quite a day at work

        Comment

        • Nerry
          New Member
          • Sep 2006
          • 14

          #5
          thx but i still had problems with it, so i decided to go with the simple validation you mentioned before:

          function isEmpty(textbox ) {
          if(textbox.valu e == "") {
          return true;
          }
          else {
          return false;
          }
          }

          the code was slightly different:

          function validate_form ( )
          {
          valid = true;
          if ( document.form1. CName.value == "" )
          {
          alert ( "Please enter your 'Company's Name'." );
          valid = false;
          }
          return valid;
          }
          in form tag - onSubmit="retur n validate_form ( );"

          this suited my purposes, thx again!

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Nerry
            thx but i still had problems with it, so i decided to go with the simple validation you mentioned before:

            function isEmpty(textbox ) {
            if(textbox.valu e == "") {
            return true;
            }
            else {
            return false;
            }
            }

            the code was slightly different:

            function validate_form ( )
            {
            valid = true;
            if ( document.form1. CName.value == "" )
            {
            alert ( "Please enter your 'Company's Name'." );
            valid = false;
            }
            return valid;
            }
            in form tag - onSubmit="retur n validate_form ( );"

            this suited my purposes, thx again!
            Simple enough. You realise of course that you no longer need the isEmpty function.

            Comment

            Working...