Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Change form action on submit

I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring Web model-view-controller (MVC) framework is 3.2.8. and I want to change the form action on a submit button. So here is my code but does not change anything at all !

<script type="text/javascript">
    $('#awardProductsButton').click(function(){
       $('#devicesFormId').attr('action', 'test');
    });
</script>

<form:form commandName="devicesForm" name="devicesForm" id="devicesFormId" method="post"     
action="${contextPath}/newdesign/manage/devices/${devicesForm.devices.id" htmlEscape="yes" enctype="multipart/form-data">   

<button id="awardProductsButton" class="btn btn-primary" type="submit">AWARD product/s</button>

 </form:form>

I also tried

$('#awardProductsButtonId').submit(function(event){
            alert ('test');
            event.preventDefault();
            $('#deviceFormId').attr('action', '${contextPath}/newdesign/manage/device/${deviceForm.device.id}');
        });

but even the alert does not show up

like image 881
Amadeu Cabanilles Avatar asked Dec 12 '25 00:12

Amadeu Cabanilles


1 Answers

you just need event.preventDefault() and .submit read-more

<script type="text/javascript">
    $('#devicesFormId').submit(function(event){
       event.preventDefault()
       $('#devicesFormId').attr('action', 'test');
       //$(this).attr('action', 'test');
    });
</script>
like image 137
codenut Avatar answered Dec 14 '25 13:12

codenut