hd.
hd.

Reputation: 18306

Replace onsubmit with jquery

I have these code below :

<form name="submissions" action="/" onsubmit="window.open('', 'foo', 'width=900,height=900,status=yes,resizable=yes,scrollbars=yes')" target="foo" method="post">
.......
<input type="submit" id="printbtn" name="printbtn" value="Print" />
<input type="submit" id="editbtn" name="editbtn" value="Edit" />
</form>

* Edited *

the window.open should only happens when the Print button is clicked. I want to remove onsubmit() event and do it with jQuery. How can I do it?

Upvotes: 4

Views: 26754

Answers (4)

jcreamer898
jcreamer898

Reputation: 8189

Will this work?

$('form[name="submissions"]').submit(function(event){
     event.preventDefault();
     // Do other stuff   
});

UPDATE: Actually, try this out...

$(function(){
    $('form[name="submissions"]').removeAttr('onsubmit')
        .submit(function(event){
            event.preventDefault();
                    // This cancels the event...
        });
    // This should fire your window opener...
    $('#printbtn').click(function(){
        window.open('', 'foo', 'width=900,height=900,status=yes,resizable=yes,scrollbars=yes');
    })

});

Should remove the onsubmit, and prevent the form from submitting...

Upvotes: 7

Joe Landsman
Joe Landsman

Reputation: 2177

If you just want to remove the onsubmit function then I think this should do the trick.

$("form[name='submissions']").attr('onsubmit', '');

Upvotes: 1

dead
dead

Reputation: 364

 $("#btn").on('click', function(e) {
  window.open('', 'foo', 'width=900,height=900,status=yes,resizable=yes,scrollbars=yes');
  e.preventDefault();

 });

Upvotes: 2

VadimAlekseev
VadimAlekseev

Reputation: 2248

$('form[name=submission]').submit(function(e) {
  e.preventDefault();
  //your code
});

Hope this helps.

Upvotes: 4

Related Questions