Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  17] [ 6]  / answers: 1 / hits: 82390  / 12 Years ago, mon, april 23, 2012, 12:00:00

Using the .NET Windows Forms WebBrowser control to show the preview of a page, I'm using the following approach described in this SO posting to disable all links on the page:



$(function() {
$('a').click(function() {
$(this).attr('href', 'javascript:void(0);');
});
});


Since the HTML page I want to show as the preview also contains HTML forms, I'm looking for a similar approach to disable all form submit functionality.



I've tried:



$(function() {
$('form').attr('onsubmit', 'return false');
});


But it seems that this doesn't work (read: still loads the page) for a form like:



<form id=myform name=myform onsubmit=return search() action=>


which I have on the page.



So my question is:



What is the best way to disable all form submit functionality on a HTML page, no matter whether it is a GET or a POST form?


More From » jquery

 Answers
56

You should be able to do:



$('form').submit(false);


From the jQuery documentation:




In jQuery 1.4.3 you can now pass in false in place of an event
handler. This will bind an event handler equivalent to: function(){
return false; }. This function can be removed at a later time by
calling: .unbind( eventName, false ).



[#86043] Sunday, April 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;