开发者

How do i change form's action property when button is clicked

I would like to change the form's action property when a button is clicked

I have two buttons in a form and when each b开发者_如何学运维utton is clicked each should post data to own url.

html:

<form method="post">
<input type="button" value="Edit Selected..." />
<input type="button" value="Delete Selected..." />
...
</form>


using jQuery

<form method="post" id="form1">
<input type="button"  data-url="action2"  value="Edit Selected..." />
<input type="button" data-url="action1" value="Delete Selected..." />
...
</form>

script:-

$(document).ready(function(){

    $('input[type*="button"]').click(function(){
    var url = $(this).attr('data-url');


     $('#form1').attr('action',url);   

    });

});


GOD it was so similar to native javascript that i missed it...

i am not sure its plane javascript or with jquery but i got the following code exactly as i needed and worked fine:

        $('#cmdDeleteButton').click(function(){
            this.form.action = "http://newurl.com";
        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜