Solved

how can I clean all inputs wiht Jquery?

Posted on 2012-04-09
3
216 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
Comment Utility
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
Comment Utility
I would simply do this:-
$(':input').val('');

Open in new window

0
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
thanks very much
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now