Reputation: 37
If user clicks on button why form doesn't submit? I tried using .prev().prev()
but it doesn't works.
HTML
<form id="my_form" action"pr.php">
<input type="text" name="cf"><span class="save_btn">Submit</span>
</form>
JQUERY
$(".save_btn").click(function(){
// Trim data
var trm = $.trim($(this).prev().val());
// Check length of data
if(trm.length == 0){
alert("Field can't be empty");
} else{
$(".save_btn").prev().prev().submit();
}
});
Upvotes: 1
Views: 36
Reputation: 2030
Try .parent()
This finds the element parent and in your case, the form element.
Upvotes: 2