javascript - How to prevent form on submit behavior in jquery? - Stack Overflow

I need to get an .click() event and prevent form from behaving as it was initially designed and make my

I need to get an .click() event and prevent form from behaving as it was initially designed and make my own changes and submit. How is it possible?

EDIT: Form input actually has an onclick defined behavior. I need to redefine it somehow.

EDIT: Some code

<form action='link' method='get'>
   <input type="image" name="name" id="id" class="class" onclick="this.form.action='some_link'" title="Title" value="" src="image.gif">
</form>

I need to get an .click() event and prevent form from behaving as it was initially designed and make my own changes and submit. How is it possible?

EDIT: Form input actually has an onclick defined behavior. I need to redefine it somehow.

EDIT: Some code

<form action='link' method='get'>
   <input type="image" name="name" id="id" class="class" onclick="this.form.action='some_link'" title="Title" value="" src="image.gif">
</form>
Share Improve this question edited Nov 17, 2010 at 17:17 Denys S. asked Nov 17, 2010 at 17:04 Denys S.Denys S. 6,53313 gold badges45 silver badges65 bronze badges 1
  • Possible duplicate of stackoverflow./questions/1263852/… or stackoverflow./questions/699065/… or many many others. – Shikiryu Commented Nov 17, 2010 at 17:10
Add a ment  | 

3 Answers 3

Reset to default 5

If you don't want it to submit the form, return false at the end of your click function. If you want to submit the form, use the form element and call the submit function on it:

$('#myFormID').submit();
$('#form').submit(function(e) {
    // Some code
});

I think it's enough.

You could use something like this (haven't tested it but it should work)

form = $("#yourform");
button = $("#yoursubmit");
button.click(function(){
             dosomething();
             form.submit();
             return false;});

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信