Replace onsubmit with jquery
Question
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?
Solution
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...
OTHER TIPS
$('form[name=submission]').submit(function(e) {
e.preventDefault();
//your code
});
Hope this helps.
$("#btn").on('click', function(e) {
window.open('', 'foo', 'width=900,height=900,status=yes,resizable=yes,scrollbars=yes');
e.preventDefault();
});
If you just want to remove the onsubmit function then I think this should do the trick.
$("form[name='submissions']").attr('onsubmit', '');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow