Reputation: 25284
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?
Upvotes: 0
Views: 4614
Reputation: 25687
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.
}
});
});
Upvotes: 1
Reputation: 162771
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>
.
Upvotes: 4
Reputation: 41858
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.
Upvotes: 1