Solved

how can I clean all inputs wiht Jquery?

Posted on 2012-04-09
3
217 Views
Last Modified: 2012-04-18
Hello Guys,

I have a form with almost 30 inputs, I have a button that I want to trigger a function where can clean all the inputs.


how can I do this ?

Thanks
0
Comment
Question by:hidrau
3 Comments
 
LVL 5

Accepted Solution

by:
Robin Hall earned 500 total points
ID: 37823653
Hidrau,

I'm not sure how you have your form set up but this is a way to do it.  In the fiddle, you can see how I've cleared all the inputs using jquery.  Clear Fields Fiddle

The heavy lifter is this bit of code:

function clearForm($form) {
    $form.find('input:text, input:password, input:file, select').val('');
    $form.find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
}

That you call on your button click and pass it the ID of your Form area.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37825153
I would simply do this:-
$(':input').val('');

Open in new window

0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 37860220
thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now