开发者

clear textbox after form submit

I have a form which posts using 开发者_JAVA百科ajax and reloads the div underneath.

I need the textbox to clear when the submit button is pressed.

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


Add an id for the textarea.

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

Hook into the submit process and add:

$('#comment').val('');


If you're not using jQuery (which is required for the solutions given above) you can replace the

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

with

document.getElementById("txtComment").value = "";


Simply call this after posting:

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

Or to improve, assign an ID to your textarea:

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

and use this after posting:

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


<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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜