views:

43

answers:

2

Hello all,

I have several forms on a page with different ids and I want to find out which is submitting and its id. How can I do this?

//stop all forms from submitting and submit the real (hidden) form#order
$('form:not(#order)').submit(function(event) {
event.preventDefault();

The above stops all forms submitting and I would like put in a conditional saying if this form, then do this etc.

Any help appreciated.

Thanks all

+2  A: 
$('form:not(#order)').submit(function(event) {
    if ($(this).attr('id') === 'someId') {
        event.preventDefault();
    }
});
Matt Huggins
+1  A: 
$('form').submit(function(event) {

    switch ( $(this).attr('id') ) {
        case 'contact':
            alert('contact us');
        break;

        case 'order':
        break;

        default:
           event.preventDefault();
        break;
    }


}


assuming all your form els have IDs.
meder