JQuery and jsFiddle cannot make PreventDefault () work in $ .submit ()

I tried to get this main function to work the last 2 hours, about 1/2 hour, which was on jsFiddle. I don’t know why, but I can’t get preventDefault()to work with the submit form button.

Here's the HTML:

<form action="" method="post">
    <input type="text" name="search-query" value="" id="search-query">
    <input type="submit" value="Search" name="submit" id="search-submit">
</form>

and here is JS:

$('#search-submit').submit(function(e) {
    e.preventDefault();
    alert("hello");
});​

When I try to use it in my own code, the form is submitted as if the preventDefault () function were not there. When I try in jsFiddle, I get this error message:

{"error": "Shell form does not validate{'html_initial_name':
u'initial-js_lib', 'form': <mooshell.forms.ShellForm object
at 0x9139fcc>, 'html_name': 'js_lib', 'label': u'Js lib', 'field':
<django.forms.models.ModelChoiceField object at 0x91392cc>,
'help_text': '', 'name': 'js_lib'}"}

(I have no idea why the error refers to mooTools since I have selected jQuery 1.7.1.) Here is jsFiddle: http://jsfiddle.net/pv2TX/11/

- ? , , , jQuery, .

+3
1

submit , . :

, . <form>.

, button:

$("#form_selector").submit(function (e) {
    e.preventDefault();
});

: http://jsfiddle.net/AvCCb/

+3

All Articles