Clear form after form post

reset form after submit react
reset form after submit javascript
jquery reset form after submit
clear form after submit php
clear form after submit angular
reset form after submit angular 8
javascript reset form
html reset form on refresh

I am trying to do something a little bit tricky.

I am trying to clear my form, inputs especially after I've submitted the form. Whatever, when I am trying to do so. The form clears but the post never executes. I want it do do both, why it is a little tricky is since I am using so I don't have to reload the page after the form post.

<script>
function submitForm() {
  $('form[name="cform"]').submit();
  $('input[type="text"], textarea').val('');
  return;
}
</script>

            <iframe name="target" style="display:none;"></iframe>
            <form name="cform" target="target" action="steamauth/chat.php" method="post">
            <input type="text" maxlength="120" name="message" style="margin-top: 1vh; margin-left: 2vh; width: 64%">
            <button type="submit" name="chat" onclick="submitForm()" style="background-color: #212223; border-radius: 4px; color: black;  border: 0px solid #4CAF50; width: 20%; height: 28px;"><font color="white">Send</font></button>
            </form> 

Is there even a solution?

Using submit() on its own simply submits the form as if the submit button was pressed with no JS present. Additionally, you'll need to use AJAX for what you're after. Try something like this (adapted from the example on https://api.jquery.com/jquery.post/):

<script>
    $('form[name="cform"]').submit(function(e) {
        e.preventDefault();

        var $form = $( this ),
            data = $form.serialize(),
            url = $form.attr( "action" );

        var posting = $.post( url, data );

        posting.done(function( data ) {
            $('input[type="text"], textarea').val('');
        });
    });
</script>

<iframe name="target" style="display:none;"></iframe>
<form name="cform" target="target" action="steamauth/chat.php" method="post">
    <input type="text" maxlength="120" name="message" style="margin-top: 1vh; margin-left: 2vh; width: 64%">
    <button type="submit" name="chat" style="background-color: #212223; border-radius: 4px; color: black;  border: 0px solid #4CAF50; width: 20%; height: 28px;"><font color="white">Send</font></button>
</form>

You'll need to further modify to take into account things like submission failures, but that should get you moving in the right direction. I recommend reading through the documentation at the link listed above for more info on callbacks (e.g. .done() in code above).

HTML DOM Form reset() Method, and Usage. The reset() method resets the values of all elements in a form ( same as clicking the Reset button). Tip: Use the submit() method to submit the form. function submitForm() { // Get the first form with the name // Usually the form name is not repeated // but duplicate names are possible in HTML // Therefore to work around the issue, enforce the correct index var frm = document.getElementsByName('contact-form')[0]; frm.submit(); // Submit the form frm.reset(); // Reset all form data return

submitForm() must return true in order to have the form actually submit.

How to clear the form filled data after submitting the form in HTML , <input type="button" onclick="submit()" value="Reset form"> How do I store form values to a json file after filling the html form and submitting it, using angularjs� Alright here is the problem. I have a text field,a submit button, and an iframe on the page. The form targets the iframe, so I pass data to it, by entering text into the field, and hitting enter

MKM's answer is correct. To clear all input types on a page, use this instead of $('input[type="text"],textarea').val(); This example clears all inputs in three forms. Tested except for select-multiple.

$(':input','#Form1','#Form2','#Form3').each(function()
{
    switch(this.type)
    {
        case "text":
        case "textarea":
        case "hidden":
        {
           this.value = ''; break;
        }
        case "radio":
        case "checkbox":
        {
            this.checked=false; break;
        }
        case "select-one":
        {
            // Set dropdowns to default value
            $(this).prop("selectedIndex", 0); break;
        }
        case "select-multiple":
        {
            $(this).prop("selectedIndex", 0); break;
        } 
        case "file":
        {
            $(this).value = ""; break;
        }
    }
});

How to reset the form fields after submit? - JavaScript, this is my html form <div class="contact_from"> <form action="#" method="post" id ="contact_form"> <!-- Message Input Area Start --> … Maybe if you get to the point where the form data is successfully processed, you could just do: $_POST = array(); Alternatively, you could do a [man]headerman redirect back to the page at that point, which would both clear the post data and also prevent the potentially unwanted reposting of form data if the user refreshes the page.

How to clear form, after submit, but after data passed?, Alright here is the problem. I have a text field,a submit button, and an iframe on the page. The form targets the iframe, so I pass data to it,� Either clear the POST data once you have done with the form - ie all inputs were ok and you have actioned whatever your result from a form is. Or, once you have determined the form is ok and have actioned whatever you action from the form, redirect the user to a new page to say "all done, thanks" etc.

How to clear form after submit in Javascript without using reset , How to clear form after submit in Javascript without using reset? Last Updated: 07 -05-2020. Forms in javascript are used to take the selective or required� It's a simple login form (username and pass) which opens a page in a new window. I'd like to clear the login details on the initial page after submitting just in case someone leaves their details in there on a public computer. I can clear the details with a simple onsubmit statement, but it doesn't actually submit them as well, so the login fails.

How to Reset a Form Using jQuery / JavaScript, You can simply use the JavaScript reset() method to reset a web form. Let's take a look <form action="/examples/html/action.php" method="post" id="myForm"> After the onsubmit event has fired and the form has been submitted (via an action="mailto:yournamehere@somebox.com") , is there a way to then clear the form, close the window or what? Is there a post submit that I can hook into via JavaScript.

Comments
  • Please comment on what you believe.
  • where's the php for this?
  • you need to use ajax btw.
  • too many unclosed questions btw.
  • the PHP don't matter, since the page is not refreshing when I click button "Send" as there is an iframe there.