Reputation: 2277
Why does the following code not work?
Example: http://jsfiddle.net/ZZe5X/18/
$('.submit').submit(function () {
e.preventDefault()
if ($('input[type="checkbox"]').is(':checked')) {
alert('ok')
} else {
alert('no')
}
})
Upvotes: 1
Views: 652
Reputation: 7797
See the tweaked example: http://jsfiddle.net/ZZe5X/33/
Upvotes: 0
Reputation: 9031
Okey:
$('.submit').submit(function () {
should be $('.submit').submit(function (e) {
submit
this should work: http://jsfiddle.net/voigtan/ZZe5X/26/
Upvotes: 1
Reputation: 2412
Please try this.
$('.submit').submit(function () {
if ($('input[type="checkbox"]').is(':checked')) {
alert('ok');
} else {
alert('no');
}
return false;
})
Upvotes: 0
Reputation: 141927
You don't have a submit button in a form with the class submit
, so your submit event handler never executes. Add class="submit"
to your form tag and change <button>Click me</button>
to <input type="submit" value="Click me" />
and move it to before your </form>
tag.
Upvotes: 0