Reputation: 13233
For some reason I'm having trouble coding in to the reset button. I have this code:
<form name="sub">
...
<button type=submit>Submit</button>
<button type=reset>Reset</button>
</form>
When I click reset, it reset's the form, as usual. However, when I try to bind a manual reset option on the button, like this code, it returns an error:
var $f = $("form[name=sub]");
$f.find("button[type=reset]").click(function(e){
e.preventDefault();
$f.reset(); // <-- Uncaught TypeError: undefined is not a function
$(window).scrollTop(0);
});
I get this error: Uncaught TypeError: undefined is not a function
Tried using document.form.sub.reset();
and tried $f =
(global variable) instead of var $f =
that doesn't work either. What's going on ?
Upvotes: 1
Views: 1524
Reputation: 11245
Then you try DOM 0
via document.form.sub.reset();
you have misprint:
document.forms.sub.reset();
You can use it in jQuery, just get access to node
:
$("form[name=sub]").find("button[type=reset]").click(function(e){
e.preventDefault();
$f.get(0).reset();//jQuery.fn.get return node, not jQuery object
$(window).scrollTop(0);
});
Upvotes: 3