javascript - Jquery Change form action on submit - Stack Overflow

I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring W

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 mandName="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

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 mandName="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

Share Improve this question edited Jan 10, 2017 at 10:53 Amadeu Cabanilles asked Jan 9, 2017 at 15:21 Amadeu CabanillesAmadeu Cabanilles 9735 gold badges21 silver badges51 bronze badges 5
  • did u try removing type="submit" attribuite from button tag? – Phoenix404 Commented Jan 9, 2017 at 15:26
  • 1 possible duplicate - stackoverflow./questions/14375144/… – John Joseph Commented Jan 9, 2017 at 15:30
  • 1 Your code works. jsfiddle/qc1fo7wq – Alexandru Severin Commented Jan 9, 2017 at 15:31
  • Well every time you click the button you prevented the submission, changed the action. You then need to actually submit the form. – T J Commented Jan 10, 2017 at 11:01
  • Possible duplicate of jQuery - prevent default, then continue default – T J Commented Jan 10, 2017 at 11:02
Add a ment  | 

1 Answer 1

Reset to default 5

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744202005a4562923.html

相关推荐

  • javascript - Jquery Change form action on submit - Stack Overflow

    I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring W

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信