Spring MVC Submit javascript

Spring MVC Submit javascript

To submit form using JavaScript you will have create input type button and onclick event call java script change action name and submit the form as below:

Input button:

<input type="button" value="Sumbit form using JavaScript" onclick="submitFormJavaScript();">

JavaScript function:

function submitFormJavaScript() {
        //form id = multiCheckBox/
              //SpringMultiCheckbox is context path of project
        document.getElementById('multiCheckBox').action = "/SpringMultiCheckbox/helloWorld.web";
        document.getElementById('multiCheckBox').submit();
    }

Spring controller mapping:

@RequestMapping(value="/helloWorld.web",
            method = RequestMethod.POST)
    public String javaScriptPost(ModelMap model,
            HttpServletRequest request) {
        //return jsp page
        return "helloWorld";

    }

 

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *