Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 301
hd. Avatar asked Oct 19 '25 09:10

hd.


1 Answers

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...

like image 162
jcreamer898 Avatar answered Oct 22 '25 03:10

jcreamer898