Clear text box after form send

I have a form in which posts use ajax and reload the div at the bottom.

I need the text box to clear when the submit button is clicked.

<form name=goform action="" method=post>
<textarea name=comment></textarea>
<input type=submit value=submit>
</form>
+3
source share
4 answers

Add idfor textarea.

<textarea name='comment' id='comment'></textarea>

Connect to the sending process and add:

$('#comment').val('');
+16
source

If you are not using jQuery (which is required for the solutions above), you can replace

$("#txtComment").val("");

from

document.getElementById("txtComment").value = "";
+1
source

:

$("textarea[name=comment]").val("");

, , :

<form name=goform action="" method=post>
<textarea id="txtComment" name="comment"></textarea>
<input type=submit value=submit>
</form>

:

$("#txtComment").val("");
0
<script>
    function testSubmit()
    {
        var x = document.forms["myForm"]["input1"];
        var y = document.forms["myForm"]["input2"];
        if (x.value === "")
        {
            alert(' fill!!');
            return false;
        } Blockquote
        if(y.value === "")
        {
            alert('plz fill the!!');
            return false;
        }
        return true;
    }
    function submitForm()
    {
        if (testSubmit())
        {
            document.forms["myForm"].submit(); //first submit
            document.forms["myForm"].reset(); //and then reset the form values
        }
    } </script> <body>
    <form method="get" name="myForm">

        First Name: <input type="text" name="input1"/>
        <br/>
        Last Name: <input type="text" name="input2"/>
        <br/>
        <input type="button" value="Submit" onclick="submitForm()"/>
    </form>

</body>
0

Source: https://habr.com/ru/post/1724810/


All Articles