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?
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting. Example: HTML.
Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.
The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!
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 ).
Use this:
<form id="myform" name="myform" onSubmit="search();return false;" action="">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With