admin管理员组文章数量:1191725
I have a form which posts using 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>
I have a form which posts using 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>
Share
Improve this question
asked Dec 5, 2009 at 12:13
mrpatgmrpatg
10.1k44 gold badges113 silver badges169 bronze badges
4 Answers
Reset to default 20Add 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>
本文标签: javascriptclear textbox after form submitStack Overflow
版权声明:本文标题:javascript - clear textbox after form submit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738441309a2086970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论