JQuery JSP Capture element is set after submit action for CSS change
I have a JSP that has jQuery and wanted to change the CSS action message to submit successfully.
So I have a page where the user enters information, submits hits, and then a span tag with an actionMessage or actionError class displayed at the top of the page (after submission). Wanted to know if I can inspect the element after the page has been submitted and add some CSS so that it renders the way I would like.
<span class="actionMessage">Yeah all go!</span>
or
<span class="actionError">Try again I didn't like that :(</span>
thanks
+1
a source to share
1 answer
You can use dispatch event to handle form submission.
$("form").submit(function () {
if (/* form_is_valid */) {
$(".actionMessage").show();
$(".actionError").hide();
return true; // Send the request to the server.
} else {
$(".actionError").show();
$(".actionMessage").hide();
return false; // Do not send the request.
}
});
Message elements should be hidden by default:
.actionMessage, .actionError {
display: none;
}
If you don't want to send the request to the server even if the request is valid, you can also return false from your submit event handler.
+1
a source to share