Reset the Value of Textarea After Form Submission

Reset the value of textarea after form submission

The problem is the HtmlHelper is retrieving the ModelState value, which is filled with the posted data. Rather than hacking round this by resetting the ModelState, why not redirect back to the [get] action. The [post] action could also set a temporary status message like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Message(int ID, string SomeText)
{
// save Text to database
SaveToDB(ID, SomeText);

TempData["message"] = "Message sent";
return RedirectToAction("Message");
}

This seems to me like more correct behaviour.

how to reset a form textarea after submiting with ajax

You're replacing the value of the textarea with a space (therefore it's not empty). Try the following:

$("body").on("keydown",function(e){
if(e.keyCode == 13){
if ($(".img_comment").is(":focus") && $(".img_comment").val() != "") {

$(".img_comment_f").ajaxForm({
success: function(response){
//alert(response);
$(".img_comment").val("");
},
error: function(){
alert("check error");
}
}).trigger("submit");
}
}
});

React-how to reset a form textarea

change null to empty string and it'll work fine

restInput= () => {
this.setState({
input :""
})
}

Empty the contents of a textarea after submit


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

Use the val() method, passing in an empty string.

Documentation: http://api.jquery.com/val

Also, your mark up is wrong. textarea isn't a self-closing element. You need a </textarea> tag. And the type="text" isn't necessary (probably not actually valid either)

As per your edit, you can either set the IDs to be static at the top of your .aspx file (I think it's ClientID="static")

Or you can use a different selector:

$('textarea').filter('[id*=CommentBox]').val('');

Reset expanding text-area's height on form submit

Add a check in your JavaScript for the length of the value of the textarea, like this:

function textAreaAdjust(o) {
o.style.height = "1px";
o.style.height = (25+o.scrollHeight)+"px";

if(o.value.length < 1){
o.style.height = "30px";
};

}

Here's a working CodePen

Textarea gives number 0 on .reset()

Personally, I would only call one function to submit the data and then after you copy the disabled fields, reset the form and set the output fields to empty.

Something like this in your appendUtdanningHøyre() function.

document.getElementById("output-år").value = '';
...
document.getElementById("reset-utdanning").reset();

How to clear the textarea after form submission

Remove the code you have that explicitly fills it with the previous data.

<?php  if (isset($_POST['message'])) { echo $_POST['message']; } ?>


Related Topics



Leave a reply



Submit