Javascript onSubmit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • trpost@gmail.com

    Javascript onSubmit

    I am trying to utilize a form to display a message and not submit when
    the submit button is clicked, here is an example on what I have done:

    <script type="text/javascript">
    <!--
    function tst()
    {
    alert('hi');
    return false;
    }
    -->
    </script>

    <form name=form1 onSubmit=tst(); >
    .....
    ....
    </form>

    When I submit the form, I get the alert message and then the page
    refreshes, what I would like is to submit and see the message and then
    be returned to the form without having it submit.
  • Conrad Lender

    #2
    Re: Javascript onSubmit

    On 2008-11-18 02:39, trpost@gmail.co m wrote:
    <form name=form1 onSubmit=tst(); >
    ....
    When I submit the form, I get the alert message and then the page
    refreshes, what I would like is to submit and see the message and then
    be returned to the form without having it submit.
    This was just answered here yesterday... Please try to at least read the
    subjects of the most recent threads.

    You need to:
    1) run your HTML through a validator before you start debugging scripts
    2) use onsubmit="retur n tst()"


    - Conrad

    Comment

    • RobG

      #3
      Re: Javascript onSubmit

      On Nov 18, 11:39 am, trp...@gmail.co m wrote:
      I am trying to utilize a form to display a message and not submit when
      the submit button is clicked, here is an example on what I have done:
      >
      <script type="text/javascript">
      <!--
      Get rid of the HTML comment demlimiters, they do nothing useful.

      function tst()
      {
              alert('hi');
              return false;}
      >
      -->
      </script>
      >
      <form name=form1 onSubmit=tst(); >
      Remember that in-line listeners are bundled into a function and called
      by the handler, they must return false to cancel submit, so:

      <form ... onsubmit="retur n tst();">


      And don't forget to put quotes around attribute vaules. They aren't
      always necessary, but it's a good habit and it is needed here. :-)


      --
      Rob

      Comment

      Working...