Thanks for help but I fail to reset my all forms :-(
$("#reset").click(function() { $("form").each(function() { $(this).reset(); }); }); also, I changed id="form" to id="frm1". On Sep 17, 2:01 am, KeeganWatkins <keeganwatk...@gmail.com> wrote: > @Dhruva- > > >> It should be $(this).reset(); > > That won't work. Note that reset() is a method that is available on > raw form elements in the DOM, but not on a jQuery-wrapped set. > > // Example for Firebug > console.log(jQuery.fn.reset) // undefined > > @pritisolanki - > You can't expect the selector engine (or your page, for that matter) > to work properly when you have several ID's that are the same. You > have three forms that all have an id="form" in your sample HTML. This > is non-compliant with W3C standards and can cause a whole mess of > problems. If you need to select them all, use the class attribute > instead. > > Furthermore, you are using the name and ID attribute in a way which > contributes to what is often called the "deadly expando". You should > definitely consider avoiding ID and name attributes such as "form", > "submit", "text", etc as described in these articles > ->http://ejohn.org/blog/deadly-expandos/andhttp://jibbering.com/faq/names/ > . "form" as an ID doesn't directly induce this phenomena, but the > principle is the same: don't use attribute values which might conflict > with DOM properties. > > Change your ID's to be unique and all should be good. For reuse, you > could create a simple plugin: > $.fn.reset = function() { > return this.each(function() { > // Check against forms, and for the reset method > if (this.tagName.toLowerCase() === "form" && this.reset) { > this.reset(); > } > }); > > } > > Usage: > $("#myForm").reset(); > > On Sep 16, 7:50 am, Dhruva Sagar <dhruva.sa...@gmail.com> wrote: > > > It should be $(this).reset(); > > But since your using an id in the selector, that will reset only the > > particular form you want. > > If you wish to reset all the forms in the page you should do something > > similar to this : > > > $('form').each(function(){ > > $(this).reset(); > > > }); > > > You should of course put this piece of code in the document ready function. > > > Thanks & Regards, > > Dhruva Sagar. > > > Pablo > > Picasso<http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html> > > - "Computers are useless. They can only give you answers." > > > On Wed, Sep 16, 2009 at 1:45 PM, pritisolanki <pritiatw...@gmail.com> wrote: > > > > Hi, > > > > I am trying to reset all the form element but it is not working can > > > someone suggest the reason. > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// > > >www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > > <html xmlns="http://www.w3.org/1999/xhtml"> > > > <head> > > > <meta http-equiv="Content-Type" content="text/html; > > > charset=ISO-8859-1" /> > > > <title>jQuery Starterkit</title> > > > > <link rel="stylesheet" type="text/css" media="screen" > > > href="screen.css" /> > > > <script src="jquery-1.3.2.min.js" type="text/javascript"></script> > > > <script src="custom.js" type="text/javascript"></script> > > > </head> > > > <body> > > > <SCRIPT LANGUAGE="JavaScript"> > > > <!-- > > > $(document).ready(function() { > > > > $("#reset").click(function() { > > > $("form").each(function() { > > > this.reset(); > > > }); > > > }); > > > > }); > > > > //--> > > > </SCRIPT> > > > > <h1>jQuery Starterkit</h1> > > > <h2>This page contains code to test the examples. Most of it is only > > > relevant for a example.</h2> > > > > <a id="first" href="#">Some link</a> > > > <br/><br/><hr/> > > > <p> > > > <p style="visibility:display">Hehehehe so think you can hide me :-p </ > > > p> > > > </p> > > > <br/><br/><hr/> > > > <form id="form" name="form1"> > > > Form 1 > > > <input name="foo" value="XXX" /> > > > </form> > > > > <form id="form" name="form2"> > > > Form 2 > > > <input name="bar" value="YYY" /> > > > </form> > > > > <form id="form" name="form3"> > > > Form 3 > > > <input type="checkbox" /> > > > <input type="checkbox" checked="checked" /> > > > </form> > > > <br/><br/><hr/> > > > <a id="reset" href="#">Reset!</a> > > > > </body> > > > </html>