SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    pg for mild peril cow's Avatar
    Join Date
    Mar 2000
    Location
    nevada, usa
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    resetting a form onSubmit...

    when i do this:

    Code:
    <form onSubmit="reset();">
    the form's information is cleared before it gets submitted. is there some way to reset the form after the form's information is submitted?

    i searched the archives and couldn't find anything on this particular function
    "There's no justice like angry mob justice!" --Seymour Skinner

  2. #2
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One possible way to do this:

    Call a JS function to actually submit your form:
    Code:
    <button name="submit" id="submit" onclick="submitForm()">
    Then, in your submitForm() function have
    PHP Code:
    document.forms[0].submit();
    document.forms[0].reset(); 
    The document.forms[0].reset() will be run before the function exits and passes control to where ever you submited the form.
    Rob Nolan
    Do or do not, there is no try.

  3. #3
    pg for mild peril cow's Avatar
    Join Date
    Mar 2000
    Location
    nevada, usa
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, i just tried that in my page but it doesn't work. the form still clears before the information is submitted.
    "There's no justice like angry mob justice!" --Seymour Skinner

  4. #4
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, thought that would work. Try this:

    Create a function called init() that you call on page load. In this function, set all the values in your form to their default (or null) values. Then, in your submitForm function, call the init() function immediately after calling form.submit(). I have several forms set up like this at work, so I know this works.
    Rob Nolan
    Do or do not, there is no try.

  5. #5
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    resetting a form onSubmit...

    Hello there,
    The reason because the form data is cleared before the form is submitted is that the 'reset()' method is much faster than the submit() method, so when you are trying to submit the form data,the reset() method have been executed before,since it takes little time to reset a form that submit it.
    If you want to reset your form every time the page containing the form is loaded,try this:

    <html>
    <head>
    <title>Reseting my Form</title>
    </head>

    <body onload="document.myform.reset()">
    <div align="center">
    <form action="action.php" name="myform">
    Inputbr>
    <input type="text" name="userinput">
    <br>
    <input type="submit" value="Submit">
    </form>
    </div>
    </body>
    </html>

    I hope this helps.

    Kindest Regards

    Alex

  6. #6
    pg for mild peril cow's Avatar
    Join Date
    Mar 2000
    Location
    nevada, usa
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks mixale it works! another simple solution...overlooked again
    "There's no justice like angry mob justice!" --Seymour Skinner

  7. #7
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    resetting a form onSubmit...

    Hello cow,
    I'm glad you were able to solve your problem.

    Best Regards.

    Alex


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •