admin管理员组

文章数量:1425752

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;});

本文标签: javascriptHow to prevent form on submit behavior in jqueryStack Overflow