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
Best Way in .Net to Manage Queue of Tasks on a Separate (Single) Thread
Enabling C# 7 in a ASP.NET Application
How Does JSON Deserialization in C# Work
Websocket Server: Onopen Function on the Web Socket Is Never Called
How to Create Custom Config Section in App.Config
Check If a Value Is in an Array (C#)
C#: Waiting for All Threads to Complete
Silent Failures in C#, Seemingly Unhandled Exceptions That Does Not Crash the Program
How to Determine If a Type Implements an Interface with C# Reflection
How to Send Text to Notepad in C#/Win32
C#: How to Make It Harder for Hacker/Cracker to Get Around or Bypass the Licensing Check
Mapping Object to Dictionary and Vice Versa
Understanding Async/Await in C#
Can a C# Class Inherit Attributes from Its Interface