Reputation: 2114
Could I somehow disable action (send, redirect) from submit if the textarea was empty (so nothing at all happens onclick). I want to avoid displaying error here, thats why I'm asking.
My textarea:
<textarea id="message" name="message" maxlength="35"></textarea>
My submit button:
<input id="send" type="image" src="/site_media/static/images/submit.png" value="Submit">
This is what i tried: http://jsfiddle.net/5Xwyb/
My brain died couple of hours ago.
Upvotes: 1
Views: 1836
Reputation: 218732
$(function(){
$("#send").submit(function(e){
if($("#message").val()==""))
{
e.preventDefault();
}
});
});
JsFiddle is here http://jsfiddle.net/5Xwyb/7/
Upvotes: 1
Reputation: 22241
Will stop all attempts to submit if #message is empty.
$(function(){
$("#send").submit(function(event){
if($("#message").val().length === 0))
event.preventDefault();
// other submit code
});
});
Upvotes: 4