views:

38

answers:

2
$('#form').submit(function(event) {

});

When user submits the form by click <input type="submit" />,it should be <input type="submit" />,

when user submits the form by pressing Enter in a <input />,it should be that <input />

I tried event.target,but it's wrong.

+2  A: 

This seems to do the trick:

$(document).ready(function() {
    var target = null;
    $('#form :input').focus(function() {
        target = this;
        alert(target);
    });
    $('#form').submit(function() {
        alert(target);
    });
});
karim79
Just verified `this.target` is wrong.
this.target is indeed wrong, just tried myself. Will remove it promptly.
karim79
@unknown (google) - I've edited the answer, it seems to work.
karim79
Thanks.I'm not sure if there is a more simple solution,though
A: 

When pressing enter in a filed or by clicking on a <input type="submit" /> it's the <form> that is submitted.

So the target is the one specified by your your <form> tag identified by #form in your example.

I'm not shure what you want to do though...

gregseth