I am saving a load of information to a database, and using jQuery to alert either a success or fail message, followed by clearing the form so the user can input a new set of data without leaving the page. My textarea posts a NULL value when I use the jQuery script, but works perfectly when I don't use the script. All other inputs in the form work just fine, and changing the text area to an input type = text also works.
<form name = "usemarkscheme" id = "usemarkscheme" method ="POST" action ="submitmarks.php">
<a few inputs here that all work>
<textarea name = "add" placeholder = "Enter additional comments here"></textarea>
</form>
This is the jQuery file:
$(document).ready(function () {
$("input#submit").click(function () {
$.post($("#usemarkscheme").attr("action"), $("#usemarkscheme: input").serializeArray(), function (data) {
if (data === "This student has already received a mark for this mark scheme!") {
alert("This student has already received a mark for this mark scheme!");
} else {
alert("Marks entered");
}
}
//close $.post
);
$("#usemarkscheme").submit(function () {
return false;
})
//close onclick function
//clear form after every student has been marked
$("#usemarkscheme").each(function () {
this.reset();
});
});
});
The error messages work well
Maybe
$("#usemarkscheme: input").serializeArray()
is fetching only the input fields. Try adding the textarea selector too. Try using
$("#usemarkscheme input, #usemarkscheme textarea").serializeArray()
or even better
$("#usemarkscheme").serializeArray()
The simply problem is you use $("#usemarkscheme: input")
and this will give you only input fealds not the textarea.
If im not wrong you have to try $("#usemarkscheme: input, #usemarkscheme textarea")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.