Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear textbox after form submit

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>
like image 333
mrpatg Avatar asked Nov 29 '22 06:11

mrpatg


2 Answers

Add an id for the textarea.

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

Hook into the submit process and add:

$('#comment').val('');
like image 171
Alan Haggai Alavi Avatar answered Dec 09 '22 18:12

Alan Haggai Alavi


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 = "";
like image 37
Ozzy Avatar answered Dec 09 '22 19:12

Ozzy