0

I have a form in my jsp file, say :

    <form action="/business/login/user" id="loginForm" method="get">
    ..............................
    ..............................
    <input type="submit" onclick="doLoginSubmit();"> 

Inside my <script> tag, i have a function called doLoginSubmit. So what will happen when i click my submit button? Will it go to controller directly or my java script function?

Is there any way that i could change the form action to another from javascript?

sreehari
  • 189
  • 6
  • 16

2 Answers2

1

Thst's HTML part, so it is evaluated on the browser side, so your browser will execute JavaScript function doLoginSubmit(). If you want to call Java method, you have to send request to your Java server.

There is answer to your second question: https://stackoverflow.com/a/2701086/3703819

Community
  • 1
  • 1
dey
  • 3,022
  • 1
  • 15
  • 25
0

This would first call the javascript defined in your script and then from there you have to specify what the script would do. You can return true or false there. If true is returned, then the form's action is executed.

You could use Ajax in your js to call a different action in the url where the path is defined in the Controller.

    $('#btnConfirm')
            .click(
                    function() {
                        var accountno = $('#deleteModal').data('id');
                        $.ajax({
                                    type : "GET",
                                    contentType : "application/json",
                                    url : "deleteAccount.json",
                                    data : {
                                        accountno : accountno
                                    },
                                    dataType : 'json',
                                    timeout : 10000,
                                    success : function(data) { ..}