submitting a page

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

    submitting a page

    I have the following:

    <input type="image" src="images/submit.jpg" width="70" height="30"
    border="0" onclick="valida teRegister()" />

    It is inside a form where:

    <form action="registe r_submit.php" name="register" id="register"
    method="post">

    At the end of validateRegiste r() I have:

    if (msg.length 0) {
    alert(msg);
    } else {
    document.regist er.submit();
    }

    after having built the msg based upon any errors. (It starts with
    var msg = '';)

    What I am happening is that it alerts the message of all the errors
    because msg.length 0, but then it submits the page!!! Even if I
    comment out the document.regist er.submit(), it still submits it.

    How can it submit the page if not a single call is made to post and
    there is not button for submit?
  • Bjoern Hoehrmann

    #2
    Re: submitting a page

    * sheldonlg wrote in comp.lang.javas cript:
    >What I am happening is that it alerts the message of all the errors
    >because msg.length 0, but then it submits the page!!! Even if I
    >comment out the document.regist er.submit(), it still submits it.
    You have to prevent the default action of the submit event. Methods how
    to do that vary between browsers, one way to do it would be to call the
    ..preventDefaul t() method on the event object where available. Another
    would be to `return false` from the code in the onsubmit attribute.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    • BootNic

      #3
      Re: submitting a page

      sheldonlg <sheldonlgwro te in
      news:ypmdnfVjed Bd9K7VnZ2dnUVZ_ gednZ2d@giganew s.com:
      I have the following:
      >
      <input type="image" src="images/submit.jpg" width="70" height="30"
      border="0" onclick="valida teRegister()" />
      Remove the onclick on the image submit.
      It is inside a form where:
      >
      <form action="registe r_submit.php" name="register" id="register"
      method="post">
      Add onsubmit="retur n validateRegiste r();" to the form.
      At the end of validateRegiste r() I have:
      >
      if (msg.length 0) {
      alert(msg);
      add return false;
      } else {
      document.regist er.submit();
      replace document.regist er.submit();
      with return true;
      }
      >
      after having built the msg based upon any errors. (It starts with
      var msg = '';)
      >
      What I am happening is that it alerts the message of all the errors
      because msg.length 0, but then it submits the page!!! Even if I
      comment out the document.regist er.submit(), it still submits it.
      Input type="image" is your submit button.
      How can it submit the page if not a single call is made to post and
      there is not button for submit?
      Your submit button is the input image.

      Javascript validation is only a courtesy to the user, do validate on the
      server.

      --
      BootNic Tuesday May 20, 2008 8:35 PM
      Don't worry about people stealing an idea. If it's original, you
      will have to ram it down their throats.
      *Howard Aiken*

      Comment

      • sheldonlg

        #4
        Re: submitting a page

        BootNic wrote:
        sheldonlg <sheldonlgwro te in
        news:ypmdnfVjed Bd9K7VnZ2dnUVZ_ gednZ2d@giganew s.com:
        >
        >I have the following:
        >>
        ><input type="image" src="images/submit.jpg" width="70" height="30"
        >border="0" onclick="valida teRegister()" />
        >
        Remove the onclick on the image submit.
        >
        >It is inside a form where:
        >>
        ><form action="registe r_submit.php" name="register" id="register"
        >method="post ">
        >
        Add onsubmit="retur n validateRegiste r();" to the form.
        >
        >At the end of validateRegiste r() I have:
        >>
        >if (msg.length 0) {
        > alert(msg);
        >
        add return false;
        >
        >} else {
        > document.regist er.submit();
        >
        replace document.regist er.submit();
        with return true;
        >
        >}
        >>
        >after having built the msg based upon any errors. (It starts with
        >var msg = '';)
        >>
        >What I am happening is that it alerts the message of all the errors
        >because msg.length 0, but then it submits the page!!! Even if I
        >comment out the document.regist er.submit(), it still submits it.
        >
        Input type="image" is your submit button.
        Thanks.
        >
        >How can it submit the page if not a single call is made to post and
        >there is not button for submit?
        >
        Your submit button is the input image.
        Uh, no, not the way I had it coded. All it is is a button that invokes
        a javascript. It knows nothing about submitting.
        >
        Javascript validation is only a courtesy to the user, do validate on the
        server.
        >

        Comment

        • sheldonlg

          #5
          Re: submitting a page

          Bjoern Hoehrmann wrote:
          * sheldonlg wrote in comp.lang.javas cript:
          >What I am happening is that it alerts the message of all the errors
          >because msg.length 0, but then it submits the page!!! Even if I
          >comment out the document.regist er.submit(), it still submits it.
          >
          You have to prevent the default action of the submit event. Methods how
          to do that vary between browsers, one way to do it would be to call the
          .preventDefault () method on the event object where available. Another
          would be to `return false` from the code in the onsubmit attribute.
          How is the default action being invoked? Nothing is labeled "submit"
          for a type and the submit() is not called.

          Comment

          • sheldonlg

            #6
            Re: submitting a page

            BootNic wrote:
            sheldonlg <sheldonlgwro te in
            news:ypmdnfVjed Bd9K7VnZ2dnUVZ_ gednZ2d@giganew s.com:
            >
            >I have the following:
            >>
            ><input type="image" src="images/submit.jpg" width="70" height="30"
            >border="0" onclick="valida teRegister()" />
            >
            Remove the onclick on the image submit.
            >
            >It is inside a form where:
            >>
            ><form action="registe r_submit.php" name="register" id="register"
            >method="post ">
            >
            Add onsubmit="retur n validateRegiste r();" to the form.
            >
            >At the end of validateRegiste r() I have:
            >>
            >if (msg.length 0) {
            > alert(msg);
            >
            add return false;
            >
            >} else {
            > document.regist er.submit();
            >
            replace document.regist er.submit();
            with return true;
            That worked. Thanks.

            Comment

            • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

              #7
              Re: submitting a page

              sheldonlg escribió:
              How is the default action being invoked? Nothing is labeled "submit"
              for a type and the submit() is not called.
              <input type="image" src="images/submit.jpg" width="70" height="30"
              border="0" onclick="valida teRegister()" />




              --
              -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
              -- Mi sitio sobre programación web: http://bits.demogracia.com
              -- Mi web de humor al baño María: http://www.demogracia.com
              --

              Comment

              • sheldonlg

                #8
                Re: submitting a page

                Álvaro G. Vicario wrote:
                sheldonlg escribió:
                >How is the default action being invoked? Nothing is labeled "submit"
                >for a type and the submit() is not called.
                >
                <input type="image" src="images/submit.jpg" width="70" height="30"
                border="0" onclick="valida teRegister()" />
                >
                http://www.w3.org/TR/html401/interac....html#h-17.4.1
                Yes, I just learned this yesterday. I thought that the only submit was
                through a submit button and that all else was handled by
                control.submit( ). Thanks.

                Comment

                Working...