I knew there is a JQuery form validation, but if there is no form, how to validate with Jquery? Say, there is a
<textarea></textarea>
, I want to send the text via AJAX instead of form. How to validate before sending?
I knew there is a JQuery form validation, but if there is no form, how to validate with Jquery? Say, there is a
<textarea></textarea>
, I want to send the text via AJAX instead of form. How to validate before sending?
Why not just validate it yourself. If there is certain requirements that you want to check, before the submission, or attach an onblur event to the textarea
and you can ensure that the data is correct.
I would opt for the onblur event as that would enable you to let the user know quickly if there is a problem.
The <textarea>
tag is not allowed outside a <form>
. What you're proposing wouldn't pass an HTML validator. Just surround your <textarea>
with a <form>
.
So you check the value before you send through AJAX.
$('input#mybutton').click(function() {
var text = $('textarea#mytextarea').val();
// Validate the text HERE
$.ajax({
type: "GET",
url: pURL,
async: false,
dataType: "html",
success: function(pReturn) {
// Process the return.
}
});
});