Solved

how can I clean all inputs wiht Jquery?

Posted on 2012-04-09
3
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

749 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