views:

185

answers:

3

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>
+1  A: 

Add an id for the textarea.

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

Hook into the submit process and add:

$('#comment').val('');
Alan Haggai Alavi
A: 

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("");
thephpdeveloper
A: 

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 = "";
Ozzy
oh, just realized the question was tagged with "jquery" so probably you are using it :)
Ozzy