Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show jquery message after clicking on submit button

Tags:

jquery

jsp

I am new to jquery and would like to learn how to show a message (e.x please wait in green color or submitting ) after clicking on the submit button.

Can you please help

like image 262
maas Avatar asked Jul 31 '10 09:07

maas


2 Answers

After you click on a submit button usually the form is submitted to the server and all client script execution stops. So unless you AJAXify your form it won't work. In order to AJAXify your form you could attach to the submit event and replace the default action:

$(function() {
    $('#theForm').submit(function() {
        // show a hidden div to indicate progression
        $('#someHiddenDiv').show();

        // kick off AJAX
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function() {
                // AJAX request finished, handle the results and hide progress
                $('#someHiddenDiv').hide();
            }
        });
        return false;
    });
});

and your markup:

<form id="theForm" action="/foo" method="post">
    <input name="foo" type="text" />
    <input type="submit" value="Go" />
</form>

<div id="someHiddenDiv" style="display: none;">Working...</div>
like image 98
Darin Dimitrov Avatar answered Oct 04 '22 21:10

Darin Dimitrov


May be this will help:

$('#submitButtonID').click(function(){
 alert('Please wait while form is submitting');
 $('#formID').submit();
});
like image 35
sTodorov Avatar answered Oct 04 '22 21:10

sTodorov